private async Task <ServiceRegistry> bootstrap(JasperRegistry registry) { var calls = await Handlers.FindCalls(registry).ConfigureAwait(false); _graph = new HandlerGraph(); _graph.AddRange(calls); _graph.Add(HandlerCall.For <SubscriptionsHandler>(x => x.Handle(new SubscriptionsChanged()))); _graph.Group(); Handlers.ApplyPolicies(_graph); Services.AddSingleton(_graph); Services.AddSingleton <IChannelGraph>(_channels); Services.AddSingleton <ILocalWorkerSender>(_localWorker); Services.AddTransient <ServiceBusActivator>(); if (registry.Logging.UseConsoleLogging) { Services.For <IBusLogger>().Use <ConsoleBusLogger>(); Services.For <ITransportLogger>().Use <ConsoleTransportLogger>(); } Services.ForSingletonOf <IDelayedJobProcessor>().UseIfNone <InMemoryDelayedJobProcessor>(); return(Services); }
private static IEnumerable <BehaviorChain> buildChains(BehaviorGraph graph) { var handlers = graph.Settings.Get <HandlerGraph>(); // TODO -- move this to a HandlerSource after we fix the duplicate calls // across HandlerSource problem. handlers.Add(HandlerCall.For <SubscriptionsHandler>(x => x.Handle(new SubscriptionRequested()))); handlers.Add(HandlerCall.For <SubscriptionsHandler>(x => x.Handle(new SubscriptionsChanged()))); handlers.Add(HandlerCall.For <SubscriptionsHandler>(x => x.Handle(new SubscriptionsRemoved()))); handlers.Add(HandlerCall.For <MonitoringControlHandler>(x => x.Handle(new TakeOwnershipRequest()))); handlers.Add(HandlerCall.For <MonitoringControlHandler>(x => x.Handle(new TaskHealthRequest()))); handlers.Add(HandlerCall.For <MonitoringControlHandler>(x => x.Handle(new TaskDeactivation()))); handlers.ApplyGeneralizedHandlers(); var policies = graph.Settings.Get <HandlerPolicies>(); handlers.ApplyPolicies(policies.GlobalPolicies); foreach (var chain in handlers) { // Apply the error handling node chain.InsertFirst(new ExceptionHandlerNode(chain)); // Hate how we're doing this, but disable tracing // on the polling job requests here. if (chain.InputType().Closes(typeof(JobRequest <>))) { chain.Tags.Add(BehaviorChain.NoTracing); } } return(handlers); }
private async Task <ServiceRegistry> bootstrap(JasperRegistry registry) { var calls = await Handlers.FindCalls(registry).ConfigureAwait(false); _graph = new HandlerGraph(); _graph.AddRange(calls); _graph.Add(HandlerCall.For <SubscriptionsHandler>(x => x.Handle(new SubscriptionsChanged()))); _graph.Group(); Handlers.ApplyPolicies(_graph); // Because the built in DI container is too stupid to just build out concrete types foreach (var type in _graph.Chains.SelectMany(x => x.Handlers).Select(x => x.HandlerType).Distinct()) { Services.AddScoped(type, type); } Services.AddSingleton(_graph); Services.AddSingleton <IChannelGraph>(_channels); Services.AddTransient <ServiceBusActivator>(); if (registry.Logging.UseConsoleLogging) { Services.For <IBusLogger>().Use <ConsoleBusLogger>(); } Services.ForSingletonOf <IDelayedJobProcessor>().UseIfNone <InMemoryDelayedJobProcessor>(); return(Services); }
public void choose_handler_type_for_call_that_returns_Task() { var handler = HandlerCall.For <TaskHandler>(x => x.Go(null)); var objectDef = handler.As <IContainerModel>().ToObjectDef(); objectDef.Type.ShouldEqual(typeof(AsyncHandlerInvoker <TaskHandler, Message>)); }
public void choose_handler_type_for_one_in_zero_out() { var handler = HandlerCall.For <ITargetHandler>(x => x.OneInZeroOut(null)); var objectDef = handler.As <IContainerModel>().ToInstance(); objectDef.ReturnedType.ShouldBe(typeof(SimpleHandlerInvoker <ITargetHandler, Input>)); }
public void choose_handler_type_for_call_that_returns_Task_of_T() { var handler = HandlerCall.For <TaskHandler>(x => x.Other(null)); var objectDef = handler.As <IContainerModel>().ToInstance(); objectDef.ReturnedType.ShouldBe(typeof(CascadingAsyncHandlerInvoker <TaskHandler, Message, Message1>)); }
public void choose_handler_type_for_one_in_one_out() { var handler = HandlerCall.For <ITargetHandler>(x => x.OneInOneOut(null)); var objectDef = handler.As <IContainerModel>().ToObjectDef(); objectDef.Type.ShouldEqual(typeof(CascadingHandlerInvoker <ITargetHandler, Input, Output>)); }
public void to_saga_types_for_a_handler_call() { var call = HandlerCall.For <SimpleSagaHandler>(x => x.Last(null)); var types = StatefulSagaConvention.ToSagaTypes(call); types.HandlerType.ShouldEqual(typeof(SimpleSagaHandler)); types.MessageType.ShouldEqual(typeof(SagaMessageThree)); types.StateType.ShouldEqual(typeof(MySagaState)); }
public void is_saga_chain_is_false_for_handler_chain_with_no_saga_handlers() { var call = HandlerCall.For<SimpleHandler<OneMessage>>(x => x.Handle(null)); var chain = new HandlerChain(); chain.AddToEnd(call); StatefulSagaConvention.IsSagaChain(chain) .ShouldBeFalse(); }
public void is_async_negative() { var chain = new HandlerChain(); chain.IsAsync.ShouldBeFalse(); chain.AddToEnd(HandlerCall.For <GreenHandler>(x => x.Handle(new Message1()))); chain.IsAsync.ShouldBeFalse(); }
public void is_saga_chain_is_true_for_handler_chain_with_a_saga_handler() { var call = HandlerCall.For<SimpleSagaHandler>(x => x.Last(null)); var chain = new HandlerChain(); chain.AddToEnd(call); StatefulSagaConvention.IsSagaChain(chain) .ShouldBeTrue(); }
public void is_saga_handler_positive() { StatefulSagaConvention.IsSagaHandler(HandlerCall.For <SimpleSagaHandler>(x => x.Start(null))) .ShouldBeTrue(); StatefulSagaConvention.IsSagaHandler(HandlerCall.For <SimpleSagaHandler>(x => x.Second(null))) .ShouldBeTrue(); StatefulSagaConvention.IsSagaHandler(HandlerCall.For <SimpleSagaHandler>(x => x.Last(null))) .ShouldBeTrue(); }
public void handler_equals() { var handler1 = HandlerCall.For <SomeHandler>(x => x.Interface(null)); var handler2 = HandlerCall.For <SomeHandler>(x => x.Interface(null)); var handler3 = HandlerCall.For <SomeHandler>(x => x.Interface(null)); handler1.ShouldBe(handler2); handler1.ShouldBe(handler3); handler3.ShouldBe(handler2); handler2.ShouldBe(handler1); }
public void could_handle() { var handler1 = HandlerCall.For <SomeHandler>(x => x.Interface(null)); var handler2 = HandlerCall.For <SomeHandler>(x => x.BaseClass(null)); handler1.CouldHandleOtherMessageType(typeof(Input1)).ShouldBeTrue(); handler2.CouldHandleOtherMessageType(typeof(Input1)).ShouldBeTrue(); handler1.CouldHandleOtherMessageType(typeof(Input2)).ShouldBeFalse(); handler1.CouldHandleOtherMessageType(typeof(Input2)).ShouldBeFalse(); }
public void SetUp() { theGraph = new HandlerGraph(); concreteCall = HandlerCall.For <ConcreteHandler>(x => x.M1(null)); concreteCall.Clone().ShouldEqual(concreteCall); concreteCall2 = HandlerCall.For <ConcreteHandler>(x => x.M2(null)); concreteCall3 = HandlerCall.For <ConcreteHandler>(x => x.M3(null)); concreteCall4 = HandlerCall.For <ConcreteHandler>(x => x.M4(null)); }
protected override void beforeEach() { theEnvelope = ObjectMother.Envelope(); theInvoker = MockFor <IChainInvoker>(); theChain = new HandlerChain(); theChain.AddToEnd(HandlerCall.For <TaskHandler>(x => x.AsyncHandle(null))); theChain.IsAsync.ShouldBeTrue(); theInvoker.Stub(x => x.FindChain(theEnvelope)) .Return(theChain); theContinuation = ClassUnderTest.Handle(theEnvelope); }
public void compile_applies_modify_chain_attributes() { var specific1 = HandlerCall.For <ConcreteHandler>(x => x.Specific1(null)); var specific2 = HandlerCall.For <ConcreteHandler>(x => x.Specific2(null)); theGraph.Add(specific1); theGraph.Add(specific2); theGraph.Compile(); theGraph.ChainFor <Concrete1>().IsWrappedBy(typeof(BlueWrapper)).ShouldBeTrue(); theGraph.ChainFor <Concrete2>().IsWrappedBy(typeof(GreenWrapper)).ShouldBeTrue(); }
public void base_class_handlers_are_applied_correctly() { var baseHandler = HandlerCall.For <ConcreteHandler>(x => x.Base(null)); var derivedHandler = HandlerCall.For <ConcreteHandler>(x => x.Derived(null)); theGraph.Add(baseHandler); theGraph.Add(derivedHandler); theGraph.ApplyGeneralizedHandlers(); theGraph.ShouldHaveCount(1); theGraph.ChainFor(typeof(DerivedMessage)).Last().ShouldBeOfType <HandlerCall>() .Equals(baseHandler).ShouldBeTrue(); }
internal Task CompileHandlers(JasperRegistry registry, PerfTimer timer) { return(Handlers.FindCalls(registry).ContinueWith(t => { timer.Record("Compile Handlers", () => { var calls = t.Result; Graph.AddRange(calls); Graph.Add(HandlerCall.For <SubscriptionsHandler>(x => x.Handle(new SubscriptionsChanged()))); Graph.Group(); Handlers.ApplyPolicies(Graph); }); })); }
private static IEnumerable <BehaviorChain> buildChains(BehaviorGraph graph) { var handlers = new HandlerGraph { HandlerCall.For <SubscriptionsHandler>(x => x.Handle(new SubscriptionRequested())), HandlerCall.For <SubscriptionsHandler>(x => x.Handle(new SubscriptionsChanged())), HandlerCall.For <SubscriptionsHandler>(x => x.Handle(new SubscriptionsRemoved())), HandlerCall.For <MonitoringControlHandler>(x => x.Handle(new TakeOwnershipRequest())), HandlerCall.For <MonitoringControlHandler>(x => x.Handle(new TaskHealthRequest())), HandlerCall.For <MonitoringControlHandler>(x => x.Handle(new TaskDeactivation())) }; handlers.Compile(); // TODO -- need to apply [ModifyChainAttribute]'s here. See GH-958 return(handlers); }
public void interfaces_are_applied_correctly() { var general = HandlerCall.For <ConcreteHandler>(x => x.General(null)); var specific1 = HandlerCall.For <ConcreteHandler>(x => x.Specific1(null)); var specific2 = HandlerCall.For <ConcreteHandler>(x => x.Specific2(null)); theGraph.Add(general); theGraph.Add(specific1); theGraph.Add(specific2); theGraph.ShouldHaveCount(2); theGraph.ApplyGeneralizedHandlers(); theGraph.ShouldHaveCount(2); theGraph.ChainFor(typeof(Concrete1)).Last().ShouldBeOfType <HandlerCall>() .InputType().ShouldEqual(typeof(IMessage)); theGraph.ChainFor(typeof(Concrete2)).Last().ShouldBeOfType <HandlerCall>() .InputType().ShouldEqual(typeof(IMessage)); }
public void applies_general_action_from_imported_graph() { var general = HandlerCall.For <ConcreteHandler>(x => x.General(null)); var specific1 = HandlerCall.For <ConcreteHandler>(x => x.Specific1(null)); var specific2 = HandlerCall.For <ConcreteHandler>(x => x.Specific2(null)); theGraph.Add(specific1); var other = new HandlerGraph(); other.Add(general); other.Add(specific2); theGraph.Import(other); theGraph.ApplyGeneralizedHandlers(); theGraph.ChainFor(typeof(Concrete1)).Last() .Equals(general).ShouldBeTrue(); theGraph.ChainFor(typeof(Concrete2)).Last() .Equals(general).ShouldBeTrue(); }
public void handler_is_async_negative() { HandlerCall.For <SomeHandler>(x => x.Interface(null)).IsAsync.ShouldBeFalse(); }
public void is_saga_handler_negative() { StatefulSagaConvention.IsSagaHandler(HandlerCall.For <SimpleHandler <OneMessage> >(x => x.Handle(null))) .ShouldBeFalse(); }
public IEnumerable <HandlerCall> FindCalls() { yield return(HandlerCall.For <MyFunkySpaceAgeProcessor>(x => x.Go(null))); }
public Task <HandlerCall[]> FindCalls(Assembly applicationAssembly) { return(Task.Factory.StartNew(() => new [] { HandlerCall.For <MyFunkySpaceAgeProcessor>(x => x.Go(null)) })); }
public void handler_is_async_positive() { HandlerCall.For <TaskHandler>(x => x.Go(null)).IsAsync.ShouldBeTrue(); HandlerCall.For <TaskHandler>(x => x.Other(null)).IsAsync.ShouldBeTrue(); }
private IEnumerable <HandlerCall> handlersForJob(Type jobType) { yield return(typeof(ScheduledJobHandlerCall <>).CloseAndBuildAs <HandlerCall>(jobType)); yield return(HandlerCall.For(typeof(SchedulingHandler <>), jobType, "Reschedule")); }
public void throws_chunks_if_you_try_to_use_a_method_with_no_inputs() { Exception <ArgumentOutOfRangeException> .ShouldBeThrownBy( () => { HandlerCall.For <ITargetHandler>(x => x.ZeroInZeroOut()); }); }
public void could_handle_is_false_for_its_own_input_type() { var handler = HandlerCall.For <ITargetHandler>(x => x.OneInOneOut(null)); handler.CouldHandleOtherMessageType(typeof(Input)).ShouldBeFalse(); }