Created
September 29, 2014 19:58
-
-
Save jordan112/2589ca6de62c38535933 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace NHA.App.Module.Attendance.Api.Infrastructure | |
{ | |
using System.Reflection; | |
using Autofac; | |
using Autofac.Integration.WebApi; | |
using NHA.App.Module.Attendance.Contract.Repositories; | |
using NHA.App.Module.Attendance.Contract.Services; | |
using NHA.App.Module.Attendance.Repository; | |
using NHA.App.Module.Attendance.Service; | |
public class AttendanceModule : Autofac.Module | |
{ | |
/// <summary> | |
/// Loads the specified builder. | |
/// </summary> | |
/// <param name="builder">The builder.</param> | |
protected override void Load(ContainerBuilder builder) | |
{ | |
// we are using AutoFac Modules: https://code.google.com/p/autofac/wiki/StructuringWithModules | |
// Register the Web API controllers. | |
builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); | |
builder.RegisterType<AttendanceService>().As<IAttendanceService>(); | |
builder.RegisterType<StudentAttendanceRepository>().As<IStudentAttendanceRepository>(); | |
// Scan an assembly for components | |
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()) | |
.Where(t => t.Name.EndsWith("Repository")) | |
.AsImplementedInterfaces(); | |
// Scan an assembly for components | |
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()) | |
.Where(t => t.Name.EndsWith("Service")) | |
.AsImplementedInterfaces(); | |
// Scan an assembly for components | |
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()) | |
.Where(t => t.Name.EndsWith("UnitOfWork")) | |
.AsImplementedInterfaces(); | |
// Scan an assembly for components | |
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()) | |
.Where(t => t.Name.EndsWith("Context")) | |
.AsImplementedInterfaces(); | |
} | |
} | |
} | |
using Owin; | |
namespace NHA.App.Module.Attendance.Api | |
{ | |
using System.Reflection; | |
using System.Web.Http; | |
using Autofac; | |
using Autofac.Integration.WebApi; | |
using NHA.App.Module.Attendance.Api.Infrastructure; | |
public class IocConfig | |
{ | |
public static void Register(HttpConfiguration config) | |
{ | |
var builder = new ContainerBuilder(); | |
//builder.RegisterApiControllers(GetLocalAssemblies()); | |
//builder.RegisterAssemblyModules(GetLocalAssemblies()); | |
builder.RegisterApiControllers(Assembly.GetExecutingAssembly()).InstancePerRequest(); | |
builder.RegisterWebApiFilterProvider(config); | |
// let's register with modules, starting with the attendance Module | |
builder.RegisterModule(new AttendanceModule()); | |
// build our container with all of our injected references | |
var container = builder.Build(); | |
// Create the dependency resolver. | |
var resolver = new AutofacWebApiDependencyResolver(container); | |
// Configure Web API with the dependency resolver. | |
config.DependencyResolver = resolver; | |
//// extend for the lifetime of the webapi calls | |
//app.UseAutofacWebApi(GlobalConfiguration.Configuration); | |
//// now inject it into our AppDomain. magic! | |
//app.UseAutofacMiddleware(container); | |
} | |
//public void ConfigureIoc(IAppBuilder app) | |
//{ | |
// var builder = new ContainerBuilder(); | |
// // Register the Web API controllers. | |
// builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); | |
// builder.RegisterApiControllers(GetLocalAssemblies()); | |
// builder.RegisterAssemblyModules(GetLocalAssemblies()); | |
// // let's register with modules, starting with the attendance Module | |
// builder.RegisterModule(new AttendanceModule()); | |
// // build our container with all of our injected references | |
// var container = builder.Build(); | |
// // Create the dependency resolver. | |
// var resolver = new AutofacWebApiDependencyResolver(container); | |
// // Configure Web API with the dependency resolver. | |
// GlobalConfiguration.Configuration.DependencyResolver = resolver; | |
// //// extend for the lifetime of the webapi calls | |
// //app.UseAutofacWebApi(GlobalConfiguration.Configuration); | |
// //// now inject it into our AppDomain. magic! | |
// //app.UseAutofacMiddleware(container); | |
//} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment