示例#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);
        }