Esempio n. 1
0
        public void ConstrainsForOpenGenerics(IFrameworkAdapter framework)
        {
            framework.RegisterTransient(typeof(IGenericService <>), typeof(GenericService <>));
            framework.RegisterTransient(typeof(IGenericService <>), typeof(GenericServiceWithIService2Constraint <>));
            var resolved = framework.ResolveAll <IGenericService <IndependentService> >().ToArray();

            Assert.Equal(1, resolved.Length);
            Assert.IsType <GenericService <IndependentService> >(resolved[0]);
        }
Esempio n. 2
0
        public void OpenGenericTypes(IFrameworkAdapter framework)
        {
            framework.RegisterTransient(typeof(IGenericService <>), typeof(GenericService <>));
            var resolved = framework.Resolve <IGenericService <int> >();

            Assert.NotNull(resolved);
        }
Esempio n. 3
0
        public void TransientLifetime(IFrameworkAdapter framework)
        {
            framework.RegisterTransient <IService, IndependentService>();
            var instance1 = framework.Resolve <IService>();
            var instance2 = framework.Resolve <IService>();

            Assert.NotSame(instance1, instance2);
        }
Esempio n. 4
0
        public void TransientFactoryUsedBySingletonStillCreatesTransient(IFrameworkAdapter framework)
        {
            framework.RegisterTransient <IService, IndependentService>();
            framework.RegisterSingleton <ServiceWithFuncConstructorDependency>();

            var service = framework.Resolve <ServiceWithFuncConstructorDependency>();
            var first   = service.Factory();
            var second  = service.Factory();

            Assert.NotSame(first, second);
        }
 public static void RegisterTransient <TService, TImplementation>(this IFrameworkAdapter container)
     where TImplementation : TService
 {
     container.RegisterTransient(typeof(TService), typeof(TImplementation));
 }