private void RegisterQueryProcessor() { var registry = new QueryHandlerRegistry(); registry.Register <ToDoByIdQuery, ToDoByIdQuery.Result, ToDoByIdQueryHandlerAsync>(); registry.Register <ToDoQueryAll, ToDoQueryAll.Result, ToDoQueryAllHandlerAsync>(); _container.Register <IQueryHandler <ToDoByIdQuery, ToDoByIdQuery.Result>, ToDoByIdQueryHandlerAsync>(Lifestyle.Scoped); _container.Register <IQueryHandler <ToDoQueryAll, ToDoQueryAll.Result>, ToDoQueryAllHandlerAsync>(Lifestyle.Scoped); var retryPolicy = Policy.Handle <Exception>().WaitAndRetryAsync(new[] { TimeSpan.FromMilliseconds(50), TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(150) }); var circuitBreakerPolicy = Policy.Handle <Exception>().CircuitBreakerAsync(1, TimeSpan.FromMilliseconds(500)); var policyRegistry = new Darker.PolicyRegistry { { QueryProcessor.RetryPolicyName, retryPolicy }, { QueryProcessor.CircuitBreakerPolicyName, circuitBreakerPolicy } }; Func <Type, object> simpleFactory = type => _container.GetInstance(type); IQueryProcessor queryProcessor = QueryProcessorBuilder.With() .Handlers(registry, simpleFactory, Activator.CreateInstance) .Policies(policyRegistry) .InMemoryRequestContextFactory() .Build(); _container.RegisterSingleton <IQueryProcessor>(queryProcessor); }
public Benchmark() { var handlerRegistry = new QueryHandlerRegistry(); handlerRegistry.Register <BasicSyncQuery, bool, BasicSyncQueryHandler>(); handlerRegistry.Register <BasicAsyncQuery, bool, BasicAsyncQueryHandler>(); _queryProcessor = QueryProcessorBuilder.With() .Handlers(handlerRegistry, t => (IQueryHandler)Activator.CreateInstance(t), t => (IQueryHandlerDecorator)Activator.CreateInstance(t)) .InMemoryQueryContextFactory() .Build(); }
public void ThrowsConfigurationExceptionWhenAddingADuplicatedRegistration() { // Arrange var handlerRegistry = new QueryHandlerRegistry(); handlerRegistry.Register <TestQueryA, object, IQueryHandler <TestQueryA, object> >(); // Act var exception = Assert.Throws <ConfigurationException>(() => handlerRegistry.Register <TestQueryA, object, IQueryHandler <TestQueryA, object> >()); // Assert exception.Message.ShouldBe($"Registry already contains an entry for {typeof(TestQueryA).Name}"); handlerRegistry.Get(typeof(TestQueryA)).ShouldNotBeNull(); handlerRegistry.Get(typeof(TestQueryB)).ShouldBeNull(); handlerRegistry.Get(typeof(TestQueryC)).ShouldBeNull(); }
public void QueryHandlerRegistry_ShouldRegister_QueryHandler() { // Arrange var queryHandlerRegistry = new QueryHandlerRegistry(); // Act queryHandlerRegistry.Register <AllBooksQuery, AllBooksQueryHandler>(); // Assert }
public void ThrowsConfigurationExceptionWhenResultTypeDoesnotMatch() { // Arrange var handlerRegistry = new QueryHandlerRegistry(); // Act var exception = Assert.Throws <ConfigurationException>(() => handlerRegistry.Register( typeof(TestQueryA), typeof(string), typeof(IQueryHandler <TestQueryA, object>))); // Assert exception.Message.ShouldBe($"Result type not valid for query {typeof(TestQueryA).Name}"); }
public void ReturnsNullForNotRegisteredHandler() { // Arrange var handlerRegistry = new QueryHandlerRegistry(); handlerRegistry.Register <TestQueryA, object, IQueryHandler <TestQueryA, object> >(); // Act var handlerType = handlerRegistry.Get(typeof(TestQueryB)); // Assert handlerType.ShouldBeNull(); }
public void ReturnsRegisteredHandler() { // Arrange var handlerRegistry = new QueryHandlerRegistry(); handlerRegistry.Register(typeof(TestQueryA), typeof(object), typeof(IQueryHandler <TestQueryA, object>)); // Act var handlerType = handlerRegistry.Get(typeof(TestQueryA)); // Assert handlerType.ShouldBe(typeof(IQueryHandler <TestQueryA, object>)); }
public void ReturnsRegisteredHandler() { // Arrange var handlerRegistry = new QueryHandlerRegistry(); handlerRegistry.Register <TestQueryA, TestQueryA.Response, IQueryHandler <TestQueryA, TestQueryA.Response> >(); // Act var handlerType = handlerRegistry.Get(typeof(TestQueryA)); // Assert handlerType.ShouldBe(typeof(IQueryHandler <TestQueryA, TestQueryA.Response>)); }
public void QueryHandlerRegistry_ShouldResolve_QueryHandler() { // Arrange var queryHandlerRegistry = new QueryHandlerRegistry(); // Act queryHandlerRegistry.Register <AllBooksQuery, AllBooksQueryHandler>(); // Assert var resolved = queryHandlerRegistry.Resolve <AllBooksQuery>(); Assert.NotNull(resolved); Assert.Equal(nameof(AllBooksQueryHandler), resolved.Name); }
private static void RegisterQueryProcessor(Container container) { var registry = new QueryHandlerRegistry(); registry.Register <GetWorksheetByIdQuery, Worksheet, GetWorksheetByIdQueryHandler>(); var decoratorRegistry = new QueryHandlerDecoratorRegistry(container); var queryHandlerFactory = new QueryHandlerFactory(container); var queryHandlerDecoratorFactory = new QueryHandlerDecoratorFactory(container); IQueryProcessor queryProcessor = QueryProcessorBuilder.With() .Handlers(registry, queryHandlerFactory, decoratorRegistry, queryHandlerDecoratorFactory) .InMemoryQueryContextFactory() .Build(); container.Register <IQueryProcessor>(() => { return(queryProcessor); }); }