public DataLoaderState CreateState( IServiceProvider services, string userKey) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (userKey == null) { throw new ArgumentNullException(nameof(userKey)); } StateObjectCollection <string> userStateObjects = GetOrCreateUserState(userKey); var requestStateObjects = new StateObjectCollection <string>(ExecutionScope.Request); var stateObjects = new[] { _globalStateObjects, userStateObjects, requestStateObjects }; return(new DataLoaderState( services, _dataLoaderDescriptors, stateObjects)); }
protected object GetStateObject(TKey key) { if (_descriptors.TryGetDescriptor(key, out IScopedStateDescriptor <TKey> descriptor)) { IServiceProvider services = _globalServices; StateObjectCollection <TKey> stateObjects = _globalStates; if (descriptor.Scope == ExecutionScope.Request) { services = _requestServices; stateObjects = _requestStates; } if (stateObjects.TryGetObject(key, out object instance)) { return(instance); } return(stateObjects.CreateObject(descriptor, _descriptors.CreateFactory(services, descriptor))); } return(null); }
public SessionManager( IServiceProvider globalServices, IEnumerable <DataLoaderDescriptor> dataLoaderDescriptors, IEnumerable <CustomContextDescriptor> customContextDescriptors) { if (dataLoaderDescriptors == null) { throw new ArgumentNullException(nameof(dataLoaderDescriptors)); } if (customContextDescriptors == null) { throw new ArgumentNullException(nameof(customContextDescriptors)); } _globalServices = globalServices ?? throw new ArgumentNullException(nameof(globalServices)); _dataLoaderDescriptors = new StateObjectDescriptorCollection <string>( dataLoaderDescriptors); _customContextDescriptors = new StateObjectDescriptorCollection <Type>( customContextDescriptors); _globalDataLoaders = new StateObjectCollection <string>( ExecutionScope.Global); _globalCustomContexts = new StateObjectCollection <Type>( ExecutionScope.Global); }
public DataLoaderProvider( IServiceProvider globalServices, IServiceProvider requestServices, StateObjectDescriptorCollection <string> descriptors, StateObjectCollection <string> globalStates) : base(globalServices, requestServices, descriptors, globalStates) { }
public CustomContextProvider( IServiceProvider globalServices, IServiceProvider requestServices, StateObjectDescriptorCollection <Type> descriptors, StateObjectCollection <Type> globalStates) : base(globalServices, requestServices, descriptors, globalStates) { }
protected StateObjectContainer( IServiceProvider globalServices, IServiceProvider requestServices, StateObjectDescriptorCollection <TKey> descriptors, StateObjectCollection <TKey> globalStates) { _globalServices = globalServices ?? throw new ArgumentNullException(nameof(globalServices)); _descriptors = descriptors ?? throw new ArgumentNullException(nameof(descriptors)); _globalStates = globalStates ?? throw new ArgumentNullException(nameof(globalStates)); _requestServices = requestServices ?? globalServices; _requestStates = new StateObjectCollection <TKey>( ExecutionScope.Request); }
public DataLoaderStateManager( IEnumerable <DataLoaderDescriptor> descriptors, int size) { if (descriptors == null) { throw new ArgumentNullException(nameof(descriptors)); } _dataLoaderDescriptors = new DataLoaderDescriptorCollection(descriptors); _cache = new Cache <StateObjectCollection <string> >( size < 10 ? 10 : size); _globalStateObjects = new StateObjectCollection <string>(ExecutionScope.Global); }
protected object GetStateObject(TKey key) { if (_descriptors.TryGetDescriptor(key, out IScopedStateDescriptor <TKey> descriptor)) { StateObjectCollection <TKey> objects = _scopes[descriptor.Scope]; if (objects.TryGetObject(key, out object instance)) { return(instance); } return(objects.CreateObject( descriptor, _descriptors.CreateFactory(_root, descriptor))); } return(null); }
protected StateObjectContainer( IServiceProvider root, StateObjectDescriptorCollection <TKey> descriptors, ISet <ExecutionScope> scopes, IEnumerable <StateObjectCollection <TKey> > objectCollections) { if (scopes == null) { throw new ArgumentNullException(nameof(scopes)); } if (objectCollections == null) { throw new ArgumentNullException(nameof(objectCollections)); } _root = root ?? throw new ArgumentNullException(nameof(root)); _descriptors = descriptors ?? throw new ArgumentNullException(nameof(descriptors)); _scopes = new Dictionary <ExecutionScope, StateObjectCollection <TKey> >(); foreach (StateObjectCollection <TKey> collection in objectCollections) { _scopes[collection.Scope] = collection; } foreach (ExecutionScope scope in scopes) { if (!_scopes.ContainsKey(scope)) { _scopes[scope] = new StateObjectCollection <TKey>(scope); } } }