Deveel.Data.Services.ServiceContainer.Resolve C# (CSharp) Method

Resolve() public method

public Resolve ( Type serviceType, object name ) : object
serviceType System.Type
name object
return object
        public object Resolve(Type serviceType, object name)
        {
            if (serviceType == null)
                throw new ArgumentNullException("serviceType");

            if (container == null)
                throw new InvalidOperationException("The container was not initialized.");

            lock (this) {
                return container.Resolve(serviceType, name, IfUnresolved.ReturnDefault);
            }
        }

Usage Example

        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);
        }