public void LifetimeTest() { var dependencies = new DependencyConfiguration(); dependencies.RegisterSingleton <IServiceTwo, ServiceImplOne>(); dependencies.Register <IRepository, RepositoryImplOne>(); var provider = new DependencyProvider(dependencies); var service1 = provider.Resolve <IServiceTwo>(); var service2 = provider.Resolve <IServiceTwo>(); var provider1 = provider; var service3 = Task.Run(() => provider1.Resolve <IServiceTwo>()); Assert.IsTrue(Equals(service3.Result, service1) && Equals(service3.Result, service2) && Equals(service1, service2)); dependencies = new DependencyConfiguration(); dependencies.Register <IServiceTwo, ServiceImplOne>(); dependencies.Register <IRepository, RepositoryImplOne>(); provider = new DependencyProvider(dependencies); service1 = provider.Resolve <IServiceTwo>(); service2 = provider.Resolve <IServiceTwo>(); service3 = Task.Run(() => provider.Resolve <IServiceTwo>()); Assert.IsFalse(Equals(service3.Result, service1) && Equals(service3.Result, service2) && Equals(service1, service2)); }
public void BasicTest() { config.RegisterSingleton <Interface1, Class1If1>(); config.Register <Interface2, Class1If2>(); DependencyProvider provider = new DependencyProvider(config); Interface1 item = null; Assert.DoesNotThrow(() => provider.ValidateConfig()); Assert.DoesNotThrow(() => item = provider.Resolve <Interface1>()); Assert.NotNull(item); Assert.AreEqual(item.GetType(), typeof(Class1If1)); }
public void ShouldRegisterSingleton() { DependencyConfiguration dependencyConfiguration = new DependencyConfiguration(); dependencyConfiguration.RegisterSingleton <AbstractBar, BarFromAbstract>(); DependencyProvider dependencyProvider = new DependencyProvider(dependencyConfiguration); var bar1 = dependencyProvider.Resolve <AbstractBar>(); var bar2 = dependencyProvider.Resolve <AbstractBar>(); Assert.AreSame(bar1, bar2); }