public void CanSetDefaultLifetimeToThreadLocalStorageLifetime() { using (var container = new IocContainer(() => new ThreadLocalLifetime())) { Assert.IsInstanceOfType(container.DefaultLifetimeFactory(), typeof(ThreadLocalLifetime)); } }
public void CanSetDefaultLifetimeToSessionLifetime() { using (var container = new IocContainer(() => new SessionLifetime())) { Assert.IsInstanceOfType(container.DefaultLifetimeFactory(), typeof(SessionLifetime)); } }
public void CanSetDefaultLifetimeToContainerLifetime() { using (var container = new IocContainer(() => new ContainerLifetime())) { Assert.IsInstanceOfType(container.DefaultLifetimeFactory(), typeof(ContainerLifetime)); } }
public void CanSetDefaultLifetimeToThreadLocalStorageLifetime() { using (var container = new IocContainer(() => new ThreadLocalLifetime())) { Assert.IsInstanceOfType(container.DefaultLifetimeFactory(), typeof(ThreadLocalLifetime)); } }
public void CachedLifetimeCanBeSetAsDefaultLifetime() { var policy = new CacheItemPolicy(); using (var container = new IocContainer(() => new CachedLifetime(policy))) { Assert.IsInstanceOfType(container.DefaultLifetimeFactory(), typeof(CachedLifetime)); } }
public void ContainerCanSetDefaultsUsingTheConstructor() { Func <ILifetime> lifetimeFactory = () => new ContainerLifetime(); var compileMode = CompileMode.Dynamic; var index = new DirectIndex(); using (var container = new IocContainer(lifetimeFactory, compileMode, index)) { Assert.IsInstanceOfType(container.DefaultLifetimeFactory(), typeof(ContainerLifetime)); Assert.IsTrue(compileMode == container.DefaultCompileMode); Assert.AreSame(index, container.Index); } }
public void ContainerIsCreatedWithCorrectDefaults() { using (var container = new IocContainer()) { // Default Lifetime Assert.IsInstanceOfType(container.DefaultLifetimeFactory(), typeof(TransientLifetime)); // Default CompileMode Assert.IsTrue(container.DefaultCompileMode == CompileMode.Delegate); // Default Index Assert.IsInstanceOfType(container.Index, typeof(DirectIndex)); } }
public void ContainerUsesTheDefaultLifetimeWhenRegistering() { using (var container = new IocContainer(() => new ContainerLifetime())) { var defaultLifetime = container.DefaultLifetimeFactory(); // Default Lifetime Assert.IsInstanceOfType(defaultLifetime, typeof(ContainerLifetime)); // Try registering with all Register methods using lifetime var result1 = container.Register <IFoo>(c => new Foo1()); var result2 = container.Register <IFoo, Foo1>("Key1"); var result3 = container.Register(typeof(IFoo), typeof(Foo1), "Key2"); Assert.IsInstanceOfType(result1.Lifetime, typeof(ContainerLifetime)); Assert.IsInstanceOfType(result2.Lifetime, typeof(ContainerLifetime)); Assert.IsInstanceOfType(result3.Lifetime, typeof(ContainerLifetime)); } }