internal SystemContext(ServiceContainer container) { scope = container.OpenScope(ContextNames.System); scope.RegisterInstance<ISystemContext>(this); EventRegistry = new EventRegistry(this); }
internal SystemContext(IConfiguration configuration, ServiceContainer container) { if (configuration == null) throw new ArgumentNullException("configuration"); Configuration = configuration; scope = container.OpenScope(ContextNames.System); scope.RegisterInstance<IConfiguration>(configuration); scope.RegisterInstance<ISystemContext>(this); EventRegistry = new EventRegistry(this); }
public void RegisterInstanceAndResolveAllFromChild() { var instance = new TestService1(); var parent = new ServiceContainer(); parent.RegisterInstance(instance); var child = parent.OpenScope("child"); var services = child.ResolveAll<ITestService>(); Assert.IsNotEmpty(services); Assert.AreEqual(1, services.Count()); }
public void RegisterInstanceAndResolveFromChild() { var instance = new TestService1(); var parent = new ServiceContainer(); parent.RegisterInstance(instance); var child = parent.OpenScope("child"); var childService = child.Resolve<ITestService>(); Assert.IsNotNull(childService); Assert.IsInstanceOf<TestService1>(childService); Assert.AreEqual(instance, childService); }
public void ResolveFromChildWithParentService() { var parent = new ServiceContainer(); parent.Register <TestService1>(); var child = parent.OpenScope("child"); child.Register <TestService2>(); var service2 = child.Resolve <TestService2>(); Assert.IsNotNull(service2); Assert.IsNotNull(service2.Service1); }
public void RegisterInstanceAndResolveAllFromChild() { var instance = new TestService1(); var parent = new ServiceContainer(); parent.RegisterInstance(instance); var child = parent.OpenScope("child"); var services = child.ResolveAll <ITestService>(); Assert.IsNotEmpty(services); Assert.AreEqual(1, services.Count()); }
public void OpenScopeAndResolveParent() { var provider = new ServiceContainer(); provider.Register <IService, ServiceOne>(); var scope = provider.OpenScope("c"); Assert.NotNull(scope); var service = provider.Resolve <IService>(); Assert.NotNull(service); Assert.IsType <ServiceOne>(service); }
public void RegisterInstanceAndResolveFromChild() { var instance = new TestService1(); var parent = new ServiceContainer(); parent.RegisterInstance(instance); var child = parent.OpenScope("child"); var childService = child.Resolve <ITestService>(); Assert.IsNotNull(childService); Assert.IsInstanceOf <TestService1>(childService); Assert.AreEqual(instance, childService); }
public void RegisterAndUnregisterFromChildScope() { var provider = new ServiceContainer(); provider.Register <IService, ServiceOne>(); Assert.True(provider.IsRegistered <IService>()); var scope = provider.OpenScope("b"); Assert.NotNull(scope); Assert.True(scope.IsRegistered <IService>()); Assert.True(scope.Unregister <IService>()); var service = scope.Resolve <IService>(); Assert.Null(service); }
public void ResolveFromChildWithParentService() { var parent = new ServiceContainer(); parent.Register<TestService1>(); var child = parent.OpenScope("child"); child.Register<TestService2>(); var service2 = child.Resolve<TestService2>(); Assert.IsNotNull(service2); Assert.IsNotNull(service2.Service1); }