protected override void Load(ContainerBuilder builder) { base.Load(builder); builder.ConfigureWebApi(GlobalConfiguration.Configuration); builder.RegisterApiControllers(_controllerAssembliesToScan); }
private static void SetAutofacWebAPIServices() { var configuration = GlobalConfiguration.Configuration; var builder = new ContainerBuilder(); // Configure the container with the integration implementations. builder.ConfigureWebApi(configuration); builder.RegisterType<DigitalAccountsUnitOfWork>() .As<IDigitalAccountsUnitOfWork>() .InstancePerLifetimeScope(); builder.RegisterType<DigitalAccountsService>() .As<IDigitalAccountsService>() .InstancePerLifetimeScope(); builder.RegisterAssemblyTypes(typeof(CuentaRepository).Assembly) .Where(t => t.Name.EndsWith("Repository")) .AsImplementedInterfaces() .InstancePerLifetimeScope(); // Register API controllers using assembly scanning. builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); var container = builder.Build(); // Set the dependency resolver implementation. var resolver = new AutofacWebApiDependencyResolver(container); configuration.ServiceResolver.SetResolver(resolver); AutofacServiceHostFactory.Container = container; }
protected void Application_Start() { HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize(); var configuration = GlobalConfiguration.Configuration; var builder = new ContainerBuilder(); builder.ConfigureWebApi(configuration); builder.RegisterControllers(typeof(MvcApplication).Assembly); builder.Register(c => CreateSessionFactory()).As<ISessionFactory>().SingleInstance(); builder.Register(c => { var sf = c.Resolve<ISessionFactory>(); var session = sf.OpenSession(); var export = new SchemaExport(SavedConfig); export.Execute(true, true, false, session.Connection, null); return session; } ).As<ISession>().SingleInstance(); builder.RegisterType<UnitOfWork>().InstancePerHttpRequest(); var container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); var resolver = new AutofacWebApiDependencyResolver(container); configuration.ServiceResolver.SetResolver(resolver); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); BundleTable.Bundles.RegisterTemplateBundles(); }
protected void Application_Start() { //autofac var configuration = GlobalConfiguration.Configuration; var builder = new ContainerBuilder(); builder.RegisterControllers(typeof(MvcApplication).Assembly); builder.RegisterModule(new AutofacModule()); builder.ConfigureWebApi(configuration); builder.RegisterApiControllers(typeof (MvcApplication).Assembly); var container = builder.Build(); var resolver = new AutofacWebApiDependencyResolver(container); configuration.ServiceResolver.SetResolver(resolver); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); BundleTable.Bundles.RegisterTemplateBundles(); }
private static void SetAutofacWebAPIServices() { var configuration = GlobalConfiguration.Configuration; var builder = new ContainerBuilder(); // Configure the container with the integration implementations. builder.ConfigureWebApi(configuration); // Register API controllers using assembly scanning. builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); builder.RegisterType<DefaultCommandBus>().As<ICommandBus>().InstancePerApiRequest(); builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerApiRequest(); builder.RegisterType<DatabaseFactory>().As<IDatabaseFactory>().InstancePerApiRequest(); builder.RegisterAssemblyTypes(typeof(CategoryRepository) .Assembly).Where(t => t.Name.EndsWith("Repository")) .AsImplementedInterfaces().InstancePerApiRequest(); var services = Assembly.Load("EFMVC.Domain"); builder.RegisterAssemblyTypes(services) .AsClosedTypesOf(typeof(ICommandHandler<>)).InstancePerApiRequest(); builder.RegisterAssemblyTypes(services) .AsClosedTypesOf(typeof(IValidationHandler<>)).InstancePerApiRequest(); var container = builder.Build(); // Set the dependency resolver implementation. var resolver = new AutofacWebApiDependencyResolver(container); configuration.ServiceResolver.SetResolver(resolver); }