protected override Registration CreateRegistrationCore <TService>(Func <TService> instanceCreator, Container container) { ScopedLifestyle lifestyle = GetDefaultScopedLifestyle(container); return(lifestyle.CreateRegistration <TService>(instanceCreator, container)); }
/// <summary> /// Registers the Entity Framework in the Simple Injector pipeline /// </summary> /// <typeparam name="TContext">The Entity Framework DbContext</typeparam> /// <param name="container">The Simple Injector Container</param> /// <param name="lifestyle">A lifestyle of the DbContext registration</param> public static void RegisterEntityFramework <TContext>(this Container container, ScopedLifestyle lifestyle) where TContext : DbContext { container.Register <ICreateDbModel, DefaultDbModelCreator>(); container.Register <DbContext, TContext>(lifestyle); var registration = lifestyle.CreateRegistration(typeof(EntityWriter), container); container.AddRegistration(typeof(EntityWriter), registration); container.AddRegistration(typeof(IUnitOfWork), registration); container.AddRegistration(typeof(IWriteEntities), registration); container.AddRegistration(typeof(IReadEntities), registration); }
public void CreateRegistrationService_WithScopedLifestylesAlways_ReturnsARegistrationThatWrapsTheOriginalLifestyle() { // Arrange ScopedLifestyle expectedLifestyle = Lifestyle.CreateHybrid(() => true, new CustomScopedLifestyle(), new CustomScopedLifestyle()); var container = ContainerFactory.New(); // Act var registration = expectedLifestyle.CreateRegistration <IUserRepository>(() => null, container); // Assert Assert.AreEqual(expectedLifestyle, registration.Lifestyle); }
protected override Registration CreateRegistrationCore <TService, TImplementation>(Container container) { ScopedLifestyle lifestyle = GetDefaultScopedLifestyle(container); return(lifestyle.CreateRegistration <TService, TImplementation>(container)); }