public ReducerSection(IActivator activator, ITypeRequest subReducer, Expression <StateSubSectionSelectionDelegate <TState, TSectionType> > sectionSelector) { m_sectionSelector = sectionSelector; m_sectionReducer = activator.Get <IReducer <TSectionType> >(subReducer); MemberExpression memberExpression = (MemberExpression)sectionSelector.Body; PropertyInfo propertyInfo = (PropertyInfo)memberExpression.Member; if (!propertyInfo.CanWrite || !propertyInfo.CanRead) { throw new NotAccessableSubSectionProperty($"The property {propertyInfo.Name} is being used as a Sub Section reducer however it is an invalid target. Any property used *MUST* be both to be able to be read and written to."); } m_getValue = (GetterDelegate)Delegate.CreateDelegate(typeof(GetterDelegate), propertyInfo.GetMethod); m_setValue = (SetterDelegate)Delegate.CreateDelegate(typeof(SetterDelegate), propertyInfo.SetMethod); }
public object Get() => _activator.Get();
public TStoreType CreateStore <TStoreType>() where TStoreType : IStore <TState> { if (m_activatorTypeRequest == null) { throw new MissingActivatorException(); } List <IReducer <TState> > reducers = new List <IReducer <TState> >(); List <IMiddleware> middlewares = new List <IMiddleware>(); List <IParameter> parameters = new List <IParameter>(); // Create activator IActivator activator = DefaultActivator.Get <IActivator>(m_activatorTypeRequest); parameters.Add(ConstantParameter.Create <IActivator>(nameof(activator), activator)); // Logging ILog logger = activator.Get <ILog>(m_loggerTypeRequest); parameters.Add(new ConstantParameter("log", logger, typeof(ILog))); foreach (ITypeRequest singletonRequest in m_singletonTypeRequests) { object instance = activator.Get(singletonRequest, parameters); IParameter parameter = new ConstantParameter("", instance, singletonRequest.Type); parameters.Add(parameter); } foreach (ITypeRequest reducerTypeRequest in m_reducers) { IReducer <TState> reducer = activator.Get <IReducer <TState> >(reducerTypeRequest, parameters); reducers.Add(reducer); } ReducerMiddleware <TState> rootDispatcher = new ReducerMiddleware <TState>(reducers); ActionDispatchDelegate next = rootDispatcher.InvokeAsync; foreach (ITypeRequest middlewareTypeRequest in m_middleware) { IParameter nextParameter = ConstantParameter.Create <ActionDispatchDelegate>("next", next); IAbstractMiddleware abstractMiddleware = activator.Get <IAbstractMiddleware>(middlewareTypeRequest, parameters.Clone(nextParameter)); switch (abstractMiddleware) { case IMiddleware middleware: next = (p) => middleware.InvokeAsync(p); break; case IMiddleware <TState> typedMiddleware: next = (p) => typedMiddleware.InvokeAsync((ActionContext <TState>)p); break; default: throw new InvalidMiddlewareException(abstractMiddleware.GetType()); } } IList <IParameter> storeParameters = parameters.Clone( ConstantParameter.Create <TState>("state", m_initialState), ConstantParameter.Create <ActionDispatchDelegate>("dispatch", next) ); TypeRequest storeRequest = new TypeRequest(typeof(TStoreType)); TStoreType store = DefaultActivator.Get <TStoreType>(storeRequest, storeParameters); return(store); }
public object Get() => _alteration.Get(_activator.Get());