public override void Load(IOptionsResolver optionsResolver, IAssemblyTypesResolver assemblyTypesResolver, IRegistrationContainer container) { var types = assemblyTypesResolver.Resolve(Assembly.GetExecutingAssembly()); container.BulkRegisterByMatchingEndName(types, "Service", RegistrationTarget.Interfaces); container.Register <IHttpContextAccessor, HttpContextAccessor>(RegistrationLifeTime.Singleton); container.RegisterFactory(c => (IUserContext) new UserContext(() => c.Resolve <IHttpContextAccessor>().HttpContext, c.Resolve <IRolePoliciesService>(), c.Resolve <IDateService>()) , RegistrationLifeTime.Singleton); }
public static IRegistrationContainer RegisterDbContext <TDbContext>(this IRegistrationContainer container, Func <string, DbContextOptions <TDbContext> > optionsBuilder) where TDbContext : DbContext { container.RegisterFactory(resolver => { var connectionStringResolver = resolver.Resolve <IConnectionStringResolver>(); var connectionString = connectionStringResolver.Resolve <TDbContext>(); return(optionsBuilder(connectionString)); }, RegistrationLifeTime.Scoped); container.Register <TDbContext>(RegistrationTarget.Self | RegistrationTarget.AbstractBases, RegistrationLifeTime.Scoped); return(container); }