public void ConstrainsForOpenGenerics(IContainerAdapter adapter) { adapter.RegisterTransient(typeof(IGenericService<>), typeof(GenericService<>)); adapter.RegisterTransient(typeof(IGenericService<>), typeof(GenericServiceWithIService2Constraint<>)); var resolved = adapter.ResolveAll<IGenericService<IndependentService>>().ToArray(); Assert.Equal(1, resolved.Length); Assert.IsType<GenericService<IndependentService>>(resolved[0]); }
public void ConstrainsForOpenGenerics(IContainerAdapter adapter) { adapter.RegisterTransient(typeof(IGenericService <>), typeof(GenericService <>)); adapter.RegisterTransient(typeof(IGenericService <>), typeof(GenericServiceWithIService2Constraint <>)); var resolved = adapter.ResolveAll <IGenericService <IndependentService> >().ToArray(); Assert.Equal(1, resolved.Length); Assert.IsType <GenericService <IndependentService> >(resolved[0]); }
public void OpenGenericTypes(IContainerAdapter adapter) { adapter.RegisterTransient(typeof(IGenericService<>), typeof(GenericService<>)); var resolved = adapter.Resolve<IGenericService<int>>(); Assert.NotNull(resolved); }
public void OpenGenericTypes(IContainerAdapter adapter) { adapter.RegisterTransient(typeof(IGenericService <>), typeof(GenericService <>)); var resolved = adapter.Resolve <IGenericService <int> >(); Assert.NotNull(resolved); }
public void TransientLifetime(IContainerAdapter adapter) { adapter.RegisterTransient <IService, IndependentService>(); var instance1 = adapter.Resolve <IService>(); var instance2 = adapter.Resolve <IService>(); Assert.NotSame(instance1, instance2); }
public void TransientFactoryUsedBySingletonStillCreatesTransient(IContainerAdapter adapter) { adapter.RegisterTransient <IService, IndependentService>(); adapter.RegisterSingleton <ServiceWithFuncConstructorDependency>(); var service = adapter.Resolve <ServiceWithFuncConstructorDependency>(); var first = service.Factory(); var second = service.Factory(); Assert.NotSame(first, second); }
public static void RegisterType <TService>(this IContainerAdapter container) { container.RegisterTransient <TService, TService>(); }
public static void RegisterTransient <TService, TImplementation>(this IContainerAdapter container) where TImplementation : TService { container.RegisterTransient(typeof(TService), typeof(TImplementation)); }
public void TransientLifetime(IContainerAdapter adapter) { adapter.RegisterTransient<IService, IndependentService>(); var instance1 = adapter.Resolve<IService>(); var instance2 = adapter.Resolve<IService>(); Assert.NotSame(instance1, instance2); }
public void TransientFactoryUsedBySingletonStillCreatesTransient(IContainerAdapter adapter) { adapter.RegisterTransient<IService, IndependentService>(); adapter.RegisterSingleton<ServiceWithFuncConstructorDependency>(); var service = adapter.Resolve<ServiceWithFuncConstructorDependency>(); var first = service.Factory(); var second = service.Factory(); Assert.NotSame(first, second); }