public void HasDependency_Transient_TService_TImplementation() { var services = new CoconaLiteServiceCollection(); services.AddTransient <IMyService, MyService>(); services.AddTransient <IYetAnotherService, YetAnotherService>(); var serviceProvider = new CoconaLiteServiceProvider(services); var instance = serviceProvider.GetService <IYetAnotherService>(); instance.Should().NotBeNull(); instance.Should().BeOfType <YetAnotherService>(); ((YetAnotherService)instance).MyService.Should().NotBeNull(); serviceProvider.Dispose(); ((YetAnotherService)instance).IsDisposed.Should().BeTrue(); ((MyService)((YetAnotherService)instance).MyService).IsDisposed.Should().BeTrue(); }
public void AddTransient_Type() { var services = new CoconaLiteServiceCollection(); services.AddTransient <IMyService, MyService>(); services.Should().HaveCount(1); services.Should().Contain(x => x.ServiceType == typeof(IMyService) && x.Factory != null); }
public void NoDependency_Transient_TService_Factory() { var services = new CoconaLiteServiceCollection(); services.AddTransient <IMyService>(_ => new MyService()); var serviceProvider = new CoconaLiteServiceProvider(services); var instance = serviceProvider.GetService <IMyService>(); instance.Should().NotBeNull(); instance.Should().BeOfType <MyService>(); var instance2 = serviceProvider.GetService <IMyService>(); instance.Should().NotBeSameAs(instance2); instance.Id.Should().NotBe(instance2.Id); serviceProvider.Dispose(); ((MyService)instance).IsDisposed.Should().BeTrue(); ((MyService)instance2).IsDisposed.Should().BeTrue(); }