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); }
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); }
public ObjectProvider(IUnityContainer container, ObjectProvider parent = null) : this(parent) { SetComponentContext(container); }
public ObjectProvider(ObjectProvider parent = null) { Parent = parent; }