예제 #1
0
        public static IServiceCollection AddStateMachine(this IServiceCollection services, Action <IInitialStateComponentBuilder, IServiceProvider> configuration)
        {
            return(services
                   .AddTransient <IStateMachine, StateMachine>()
                   .AddTransient <IStateMachineCore>(provider =>
            {
                var component = new StateComponentCollection();
                var builder = new InitialStateComponentBuilder(component, provider);
                configuration?.Invoke(builder, provider);

                return new StateMachineCore(builder.InitialState, component);
            }));
        }
예제 #2
0
        public IStateMachineFactoryBuilder <TKey> AddStateMachine(TKey key, Action <IInitialStateComponentBuilder> configuration)
        {
            this.Remove(key);
            this.stateMachines.Add(key, new Func <IServiceProvider, IStateMachineCore>(provider =>
            {
                var component = new StateComponentCollection();
                var builder   = new InitialStateComponentBuilder(component, provider);
                configuration.Invoke(builder);

                return(new StateMachineCore(builder.InitialState, component));
            }));

            return(this);
        }