public void Register(ContainerBuilder builder, SmartConfig config) { builder.RegisterType<Context.SampleDbContext>().As<DbContext>().InstancePerLifetimeScope(); builder.RegisterType<Context.OtherDbContext>().As<Context.IOtherDbContext>().InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(EFRepository<>)).As(typeof(IRepository<>)).InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(EFRepository<,>)).As(typeof(IRepository<,>)).InstancePerLifetimeScope(); }
public static IContainerManager Initialize(SmartConfig config = null, bool forceRecreate = false) { if (Singleton<IContainerManager>.Instance == null || forceRecreate) { var container = new ContainerManager(); container.Initialize(config); Singleton<IContainerManager>.Instance = container; } return Singleton<IContainerManager>.Instance; }
public static IContainerManager InitializeMvc(this Core.SmartContext context, SmartConfig config = null, bool forceRecreate = false) { // 删除不必要的HTTP响应头 "X-AspNetMvc-Version" MvcHandler.DisableMvcResponseHeader = true; var icm = Core.SmartContext.Initialize(config, forceRecreate); var cm = icm as ContainerManager; if (cm != null) { DependencyResolver.SetResolver(new AutofacDependencyResolver(cm._container)); } return cm; }
public void Register(ContainerBuilder builder, SmartConfig config) { //Controllers builder.RegisterFilterProvider(); builder.RegisterControllers(config.TypeFinder.Assemblies.ToArray()); }