예제 #1
0
        static async Task <int> Main(string[] args)
        {
            var streamStore = new InMemoryStreamStore();
            var somethings  = new UnitOfWorkSomethingRepository(streamStore);
            var dispatcher  = new Dispatcher();

            using var host = new WebHostBuilder()
                             .UseKestrel()
                             .ConfigureServices(services => services.AddHttpContextAccessor())
                             .Start();

            var httpContextAccessor = host.Services.GetService <IHttpContextAccessor>();

            dispatcher.Subscribe(
                Handler.Of <MessageEnvelope <DoSomething> >()
                .Log()
                .UseUnitOfWork(streamStore, httpContextAccessor)
                .RequiresAnyClaim(new Claim("role", "something-doer"))
                .Handle(CommandHandlers.DoSomething(somethings).Wrap(x => x.SubjectId)));
            dispatcher.Subscribe(
                Handler.Of <MessageEnvelope <DoSomethingElse> >()
                .Log()
                .UseUnitOfWork(streamStore, httpContextAccessor)
                .RequiresAllClaims(new Claim("role", "something-doer"), new Claim("role", "somethingelse-doer"))
                .Handle(CommandHandlers.DoSomethingElse(somethings).Wrap(x => x.SubjectId)));

            await host.RunAsync();

            return(0);
        }
예제 #2
0
        public static Handler <DoSomething> DoSomething(UnitOfWorkSomethingRepository somethings)
        => (message, ct) =>
        {
            var something = Something.Happens(new SomethingIdentifier(message.SomethingId));

            somethings.Add(something);

            return(Task.CompletedTask);
        };