Permalink
Browse files

Merge pull request #38 from pcibraro/master

Extension method for registering controllers in AutoFac
  • Loading branch information...
pedroreys committed Apr 5, 2012
2 parents 0bff93a + 313f442 commit 6729084880d080d1250251c47a2b07c8b34ade0b
@@ -0,0 +1,19 @@
+using System.Reflection;
+using System.Web.Http.Controllers;
+using Autofac;
+using Autofac.Builder;
+using Autofac.Features.Scanning;
+
+namespace WebApiContrib.IoC.AutoFac
+{
+ public static class RegistrationExtensions
+ {
+ public static IRegistrationBuilder<object, ScanningActivatorData, DynamicRegistrationStyle>
+ RegisterApiControllers(this ContainerBuilder builder, params Assembly[] controllerAssemblies)
+ {
+ return from t in builder.RegisterAssemblyTypes(controllerAssemblies)
+ where typeof(IHttpController).IsAssignableFrom(t) && t.Name.EndsWith("Controller")
+ select t;
+ }
+ }
+}
@@ -70,6 +70,7 @@
<ItemGroup>
<Compile Include="AutoFacResolver.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="RegistrationExtensions.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
@@ -83,4 +84,4 @@
<Target Name="AfterBuild">
</Target>
-->
-</Project>
+</Project>

0 comments on commit 6729084

Please sign in to comment.