예제 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();
            services.AddServerSideBlazor();
            services.AddDbContext <AppDbContext>(options =>
                                                 options
                                                 .UseSqlite(Configuration.GetConnectionString("DefaultConnection"))
                                                 .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking));
            //Handlers
            var handlers = new HandlerRegistrar();

            handlers
            .AddEntityHandlers()
            .Add(async(Request.SaveChanges _, AppDbContext context, CancellationToken cancellationToken) =>
            {
                try
                {
                    await context.SaveChangesAsync(cancellationToken);
                    return(true);
                }
                catch (DbUpdateException)
                {
                    return(false);
                }
            }
                 );
            services.AddSingleton(handlers);
        }
예제 #2
0
 public static HandlerRegistrar AddEntityHandlers(this HandlerRegistrar registrar)
 {
     return(registrar
            .Add(typeof(Add <>))
            .Add(typeof(Delete <>))
            .Add(typeof(Find <>))
            .Add(typeof(GetAll <>)));
 }
예제 #3
0
        public RazorLikeHtmlGenerator()
        {
            HandlerRegistrar.Register<EmptyHandler>();
            HandlerRegistrar.Register<CanvasSaveHandler>();
            HandlerRegistrar.Register<SavedDataHandler>();

            HandlerRegistrar.Register<RazorJsHandler>();

            //default:
            HandlerRegistrar.Register<JsHandler>();
            HandlerRegistrar.Register<RazorHandler>();
        }
예제 #4
0
        static async Task Main()
        {
            // NA PODSTAWIE
            //https://devstyle.pl/2016/11/10/cqrsdi-implementacja-w-c-i-autofac/

            // MIGRATION
            // dotnet ef migrations add Init

            // RUN
            // docker run -e MYSQL_ROOT_PASSWORD=password -p 3306:3306 -d dnhsoft/mysql-utf8
            // dotnet ef database update

            var eventHandlerRegistrar = new HandlerRegistrar <IEventHandler>();

            eventHandlerRegistrar.Register <PersonSaved>(new PersonListEventsHandler());
            eventHandlerRegistrar.Register <AddressSaved>(new PersonListEventsHandler());
            eventHandlerRegistrar.Register <PersonSaved>(new PersonDetailsEventHandler());
            var eventBus = new EventsBus(eventHandlerRegistrar);

            var commandHandlerRegistrar = new HandlerRegistrar <ICommandHandler>();

            commandHandlerRegistrar.Register <SavePerson>(new SavePersonCommandHandler(eventBus));
            commandHandlerRegistrar.Register <SaveAddress>(new SaveAddressCommandHandler(eventBus));
            var commandBus = new CommandBus(commandHandlerRegistrar);

            Console.WriteLine("Saving person...");
            await commandBus.Send(new SavePerson("Jan", "Kowalski"));

            Console.WriteLine("Saving addresses...");
            await commandBus.Send(new SaveAddress(1, "Bielsko-Biała", "43-300", "Willowa", "2", AddressType.Main));

            await commandBus.Send(new SaveAddress(1, "Bielsko-Biała", "43-300", "Bystrzańska", "100"));

            await commandBus.Send(new SaveAddress(1, "Bielsko-Biała", "43-300", "Rynek", "10"));

            Console.WriteLine("Saving person...");
            await commandBus.Send(new SavePerson("Adam", "Nowak"));

            await commandBus.Send(new SaveAddress(2, "Katowice", "43-300", "Mikołowska", "222c", AddressType.Main));

            Console.WriteLine("Data saved");
        }
예제 #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();
            services.AddServerSideBlazor();
            services.AddSingleton <WeatherForecastService>();
            //MVU# Setup
            services.AddScoped(typeof(MvuProgram <, , ,>));
            //Services
            services.AddSingleton(new RandomGenerator());
            //Handlers
            var handlers = new HandlerRegistrar();

            handlers.Add(async(Request.RandomInt _, RandomGenerator generator, CancellationToken cancellationToken) =>
            {
                var random = generator.RandomInt(0, 100);
                await Task.Delay(random * 20, cancellationToken);
                return(random);
            });
            services.AddSingleton(handlers);
        }
예제 #6
0
        static void Main()
        {
            var queryHandlerRegistrar = new HandlerRegistrar <IQueryHandler>();

            queryHandlerRegistrar.Register <GetPersonList>(new PersonHandler());
            queryHandlerRegistrar.Register <GetPersonDetails>(new PersonHandler());
            var queryBus = new QueryBus(queryHandlerRegistrar);

            var people = queryBus.Query <GetPersonList, IEnumerable <PersonListItemRecord> >(new GetPersonList());

            Console.WriteLine("People");

            foreach (var person in people.Result)
            {
                Console.WriteLine($"{person.Id} {person.LastName} {person.AddressesCount}");
            }

            Console.WriteLine("Person with id = 1");

            var personDetails = queryBus.Query <GetPersonDetails, PersonDetailsRecord>(new GetPersonDetails(1));

            Console.WriteLine($"{personDetails.Result.FirstName} {personDetails.Result.LastName}");
        }
예제 #7
0
 void RegisterMessageHandlers()
 {
     Log.Entered();
     HandlerRegistrar.Register(Session.MessageDomain, (ushort)Messages.MessageType.LoginRequest, HandleLoginRequest);
 }
예제 #8
0
파일: Mediator.cs 프로젝트: rglezg/MvuSharp
 public Mediator(ServiceFactory serviceFactory, CancellationToken cancellationToken)
 {
     _factory           = serviceFactory;
     _cancellationToken = cancellationToken;
     _handlers          = serviceFactory.GetService <HandlerRegistrar>();
 }
예제 #9
0
 public Mediator(ServiceFactory serviceFactory)
 {
     _factory  = serviceFactory;
     _handlers = serviceFactory.GetService <HandlerRegistrar>();
 }