Register() public method

public Register ( ServiceRegistration registration ) : void
registration ServiceRegistration
return void
Ejemplo n.º 1
0
        public void RegisterAndResolveFromChild()
        {
            var parent = new ServiceContainer();
            parent.Register<TestService1>();

            var child = parent.OpenScope("child");

            var childService = child.Resolve<ITestService>();
            var parentService = parent.Resolve<ITestService>();

            Assert.IsNotNull(childService);
            Assert.IsInstanceOf<TestService1>(childService);

            Assert.IsNotNull(parentService);
            Assert.IsInstanceOf<TestService1>(parentService);

            Assert.AreEqual(parentService, childService);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public void RegisterNonInstantiableService()
        {
            var provider = new ServiceContainer();

            Assert.Throws <ServiceException>(() => provider.Register <IService>());
        }
Ejemplo n.º 4
0
        public void RegisterNullService()
        {
            var provider = new ServiceContainer();

            Assert.Throws <ArgumentNullException>(() => provider.Register(null));
        }