Beispiel #1
0
        static ICommandDispatcher Configure()
        {
            Uri uri = new Uri("http://localhost:52933/api/personalDetails");
            ServiceCollection            serviceCollection  = new ServiceCollection();
            CommandingDependencyResolver dependencyResolver = serviceCollection.GetCommandingDependencyResolver(() => _serviceProvider);

            ICommandRegistry registry = dependencyResolver.UseCommanding();

            dependencyResolver.UseHttpCommanding();
            _serviceProvider = serviceCollection.BuildServiceProvider();

            IHttpCommandDispatcherFactory httpCommandDispatcherFactory = _serviceProvider.GetService <IHttpCommandDispatcherFactory>();

            registry.Register <UpdatePersonalDetailsCommand, UpdateResult>(() => httpCommandDispatcherFactory.Create(uri, HttpMethod.Put));

            ICommandDispatcher dispatcher = _serviceProvider.GetService <ICommandDispatcher>();

            return(dispatcher);
        }
        public static IServiceCollection UseStore(this IServiceCollection serviceCollection,
                                                  Func <IServiceProvider> serviceProvider,
                                                  ICommandRegistry commandRegistry, ApplicationModeEnum applicationMode = ApplicationModeEnum.InProcess)
        {
            serviceCollection.AddSingleton <IStoreProductRepository, StoreProductRepository>();
            if (applicationMode == ApplicationModeEnum.InProcess || applicationMode == ApplicationModeEnum.Server)
            {
                commandRegistry.Register <GetStoreProductQueryHandler>();
            }
            else if (applicationMode == ApplicationModeEnum.Client)
            {
                // this configures the command dispatcher to send the command over HTTP and wait for the result
                Uri functionUri = new Uri("http://localhost:7071/api/GetStoreProduct");
                commandRegistry.Register <GetStoreProductQuery, CommandResponse <StoreProduct> >(() =>
                {
                    IHttpCommandDispatcherFactory httpCommandDispatcherFactory = serviceProvider().GetService <IHttpCommandDispatcherFactory>();
                    return(httpCommandDispatcherFactory.Create(functionUri, HttpMethod.Get));
                });
            }

            serviceCollection.RegisterValidators();

            return(serviceCollection);
        }