public void Register(ContainerBuilder builder, ITypeFinder typeFinder, SmdConfig config) { builder.RegisterGeneric(typeof(SmdRoleStore <,>)).As(typeof(Microsoft.AspNetCore.Identity.IRoleStore <>)).InstancePerLifetimeScope(); builder.RegisterType <RoleStore>().InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(SmdRoleManager <,>)).As(typeof(Microsoft.AspNetCore.Identity.RoleManager <>)).InstancePerLifetimeScope(); builder.RegisterType <RoleManager>().InstancePerLifetimeScope(); builder.RegisterType <UserStore>().InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(SmdUserManager <,>)).As(typeof(Microsoft.AspNetCore.Identity.UserManager <>)).InstancePerLifetimeScope(); builder.RegisterType <UserManager>().InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(SmdSignInManager <,>)).As(typeof(Microsoft.AspNetCore.Identity.SignInManager <>)).InstancePerLifetimeScope(); builder.RegisterType <SignInManager>().InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(SmdUserClaimsPrincipalFactory <,>)).As(typeof(Microsoft.AspNetCore.Identity.UserClaimsPrincipalFactory <,>)).InstancePerLifetimeScope(); builder.RegisterType <UserClaimsPrincipalFactory>().InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(SmdSecurityStampValidator <,>)).As(typeof(Microsoft.AspNetCore.Identity.SecurityStampValidator <>)).InstancePerLifetimeScope(); builder.RegisterType <SecurityStampValidator>().InstancePerLifetimeScope(); // builder.RegisterGeneric(typeof(PermissionChecker)).As<IPermissionChecker>().InstancePerLifetimeScope(); builder.RegisterType <PermissionChecker>().As <IPermissionChecker>().InstancePerLifetimeScope(); // builder.RegisterType<PermissionChecker>().InstancePerLifetimeScope(); }
/// <summary> /// Register dependencies using Autofac /// </summary> /// <param name="nopConfig">Startup Nop configuration parameters</param> /// <param name="services">Collection of service descriptors</param> /// <param name="typeFinder">Type finder</param> protected virtual IServiceProvider RegisterDependencies(SmdConfig nopConfig, IServiceCollection services, ITypeFinder typeFinder) { var containerBuilder = new ContainerBuilder(); //register engine containerBuilder.RegisterInstance(this).As <IEngine>().SingleInstance(); //register type finder containerBuilder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance(); //find dependency registrars provided by other assemblies var dependencyRegistrars = typeFinder.FindClassesOfType <IDependencyRegistrar>(); //create and sort instances of dependency registrars var instances = dependencyRegistrars //.Where(dependencyRegistrar => PluginManager.FindPlugin(dependencyRegistrar)?.Installed ?? true) //ignore not installed plugins .Select(dependencyRegistrar => (IDependencyRegistrar)Activator.CreateInstance(dependencyRegistrar)) .OrderBy(dependencyRegistrar => dependencyRegistrar.Order); //register all provided dependencies foreach (var dependencyRegistrar in instances) { dependencyRegistrar.Register(containerBuilder, typeFinder, nopConfig); } //populate Autofac container builder with the set of registered service descriptors containerBuilder.Populate(services); //create service provider _serviceProvider = new AutofacServiceProvider(containerBuilder.Build()); return(_serviceProvider); }
public void Register(ContainerBuilder builder, ITypeFinder typeFinder, SmdConfig config) { builder.RegisterType <CachingConfiguration>().As <ICachingConfiguration>().InstancePerLifetimeScope(); builder.RegisterType <SmdMemoryCacheManager>().As <ICacheManager>().InstancePerLifetimeScope(); builder.RegisterType <SettingsConfiguration>().As <ISettingsConfiguration>().SingleInstance(); builder.RegisterType <SettingDefinitionManager>().As <ISettingDefinitionManager>().InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(TypedCacheWrapper <,>)).As(typeof(ITypedCache <,>)).InstancePerLifetimeScope(); builder.RegisterType <SettingManager>().As <ISettingManager>().InstancePerLifetimeScope(); builder.RegisterType <PermissionManager>().As <IPermissionManager>().InstancePerLifetimeScope(); }
public void Register(ContainerBuilder builder, ITypeFinder typeFinder, SmdConfig config) { builder.RegisterGeneric(typeof(EfCoreRepositoryBase <, ,>)).As(typeof(IRepository <,>)).InstancePerLifetimeScope(); builder.RegisterType <EfCoreAsyncQueryableExecuter>().As <IAsyncQueryableExecuter>().InstancePerLifetimeScope(); }