示例#1
0
        public IObjectProvider CreateScope(IServiceCollection serviceCollection)
        {
            var objectProvider = new ObjectProvider(this);
            var childScope     = UnityContainer.CreateChildContainer();

            childScope.RegisterInstance <IObjectProvider>(objectProvider);
            childScope.RegisterInstance(childScope.BuildServiceProvider(serviceCollection));
            objectProvider.SetComponentContext(childScope as UnityContainer);
            return(objectProvider);
        }
示例#2
0
        public IObjectProvider CreateScope(Action <IObjectProviderBuilder> buildAction)
        {
            if (buildAction == null)
            {
                throw new ArgumentNullException(nameof(buildAction));
            }

            var objectProvider = new ObjectProvider(this);
            var childScope     = UnityContainer.CreateChildContainer() as UnityContainer;

            childScope.RegisterInstance <IObjectProvider>(objectProvider);
            var providerBuilder = new ObjectProviderBuilder(childScope);

            buildAction(providerBuilder);
            childScope.RegisterInstance(childScope.BuildServiceProvider(new ServiceCollection()));
            objectProvider.SetComponentContext(childScope);
            return(objectProvider);
        }
        public IObjectProvider Build(IServiceCollection serviceCollection = null)
        {
            serviceCollection = serviceCollection ?? new ServiceCollection();
            _container.BuildServiceProvider(serviceCollection);

            Register <IObjectProvider>(context =>
            {
                var provider = context as ObjectProvider;
                if (provider == null)
                {
                    throw new Exception("object provider is not Unity ObjectProvider!");
                }

                return(new ObjectProvider(provider.UnityContainer));
            }, ServiceLifetime.Scoped);

            var objectProvider = new ObjectProvider(_container);

            return(objectProvider);
        }
示例#4
0
 public ObjectProvider(IUnityContainer container, ObjectProvider parent = null)
     : this(parent)
 {
     SetComponentContext(container);
 }
示例#5
0
 public ObjectProvider(ObjectProvider parent = null)
 {
     Parent = parent;
 }