public void TestContainerResolveInstance() { var container = new TinyContainer(); container.RegisterTransient <SimpleDependency>(); var dependency1 = container.Resolve <SimpleDependency>(); Assert.IsNotNull(dependency1); Assert.IsInstanceOfType(dependency1, typeof(SimpleDependency)); Assert.AreEqual(SimpleDependency.ActiveDependecies, 1); Assert.AreEqual(SimpleDependency.ResolveCounter, 1); var dependency2 = container.Resolve <SimpleDependency>(); Assert.IsNotNull(dependency2); Assert.IsInstanceOfType(dependency2, typeof(SimpleDependency)); Assert.AreEqual(SimpleDependency.ActiveDependecies, 2); Assert.AreEqual(SimpleDependency.ResolveCounter, 2); Assert.AreNotSame(dependency1, dependency2); container.Dispose(); Assert.AreEqual(SimpleDependency.ActiveDependecies, 0); }
public void ExtensionMethods() { var container = new TinyContainer(); new MyModule().RegisterServices(container); // or container.RegisterModule(new MyModule()); // or container.RegisterModule <MyOtherModule>(); Assert.IsNotNull(container.Resolve <Simple>()); Assert.IsNotNull(container.Resolve <ISimple>()); }
public void TestContainerResolveSingleton() { var container = new TinyContainer(); container.RegisterSignleton <SimpleDependency>(); var result1 = container.Resolve <SimpleDependency>(); var result2 = container.Resolve <SimpleDependency>(); Assert.AreSame(result1, result2); Assert.AreEqual(SimpleDependency.ActiveDependecies, 1); container.Dispose(); }
public void Basic() { var container = new TinyContainer(); new MyModule().RegisterServices(container); Assert.IsNotNull(container.Resolve <Simple>()); }
public void Class() { var tiny = new TinyContainer(); tiny.Register <Simple>(); Assert.IsNotNull(tiny.Resolve <Simple>()); }
public void WithFactory() { var tiny = new TinyContainer(); tiny.Register(factory => new Simple()); Assert.IsNotNull(tiny.Resolve <Simple>()); }
public void Interface() { var tiny = new TinyContainer(); tiny.Register <ISimple, Simple>(); Assert.IsNotNull(tiny.Resolve <ISimple>()); }
public void Delegate() { var tiny = new TinyContainer(); tiny.Register <Simple>() .Register <Func <Simple> >(factory => factory.Resolve <Simple>); Assert.IsNotNull(tiny.Resolve <Func <Simple> >()()); }
public void ComplexClass() { var tiny = new TinyContainer(); tiny.Register <Simple>() .Register <ISimple, Simple>() .Register <Func <Simple> >(factory => () => new Simple()) .Register <IComplex, Complex>(); var simpleInstance = tiny.Resolve <IComplex>(); Assert.IsNotNull(simpleInstance); }
public void TestResolitionWithAutowiring() { var container = new TinyContainer(); container.RegisterTransient <ITestDependency, SimpleDependency>() .RegisterTransient <CompositeDependecy>(); var dependency = container.Resolve <CompositeDependecy>(); Assert.IsNotNull(dependency); Assert.IsInstanceOfType(dependency, typeof(CompositeDependecy)); Assert.IsNotNull(dependency.InnerDependency); Assert.IsInstanceOfType(dependency.InnerDependency, typeof(SimpleDependency)); container.Dispose(); Assert.IsNull(dependency.InnerDependency); // Checking that dependecny was disposed }
public static TDependency Resolve <TDependency>(this TinyContainer container) { return((TDependency)container.Resolve(typeof(TDependency))); }