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 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 merging_matching_chains_merges_the_handlers_for_the_same_message() { theGraph.Add(concreteCall); var other = new HandlerGraph(); other.Add(concreteCall2); other.Add(concreteCall3); theGraph.Import(other); theGraph.ShouldHaveCount(1); var chain = theGraph.ChainFor(typeof(Input)); chain.ElementAt(0).Equals(concreteCall).ShouldBeTrue(); chain.ElementAt(1).Equals(concreteCall2).ShouldBeTrue(); chain.ElementAt(2).Equals(concreteCall3).ShouldBeTrue(); }
public void merging_adds_a_chain_for_all_new_message_type() { theGraph.Add(concreteCall); var other = new HandlerGraph(); other.Add(concreteCall4); theGraph.Import(other); theGraph.Select(x => x.InputType()) .ShouldHaveTheSameElementsAs(typeof(Input), typeof(DifferentInput)); }
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 CompilationContext() { _container = new Lazy <IContainer>(() => { var registry = new Registry(); registry.Populate(services); return(new Container(registry)); }); _graph = new Lazy <HandlerGraph>(() => { rules = new GenerationRules("Jasper.Testing.Codegen.Generated"); rules.Sources.Add(new ServiceGraph(services)); rules.Sources.Add(new NoArgConcreteCreator()); rules.Assemblies.Add(typeof(IContainer).GetTypeInfo().Assembly); rules.Assemblies.Add(GetType().GetTypeInfo().Assembly); var graph = new HandlerGraph(); var methods = typeof(T).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static) .Where(x => x.DeclaringType != typeof(object) && x != null && x.GetParameters().Any() && !x.IsSpecialName); foreach (var method in methods) { graph.Add(new HandlerCall(typeof(T), method)); } return(graph); }); _code = new Lazy <string>(() => Graph.GenerateCode(rules)); _handlers = new Lazy <Dictionary <Type, MessageHandler> >(() => { var handlers = Graph.CompileAndBuildAll(rules, _container.Value.GetInstance); var dict = new Dictionary <Type, MessageHandler>(); foreach (var handler in handlers) { dict.Add(handler.Chain.MessageType, handler); } return(dict); }); }
public Task<BehaviorChain[]> BuildChains(BehaviorGraph graph, IPerfTimer timer) { var finders = HandlerSources.Select(x => x.FindCalls(graph.ApplicationAssembly)).ToArray(); return Task.WhenAll(finders).ContinueWith(all => { var handlers = new HandlerGraph(); var allCalls = all.Result.SelectMany(x => x).Distinct(); handlers.Add(allCalls); handlers.Compile(); return handlers.OfType<BehaviorChain>().ToArray(); }); }
public CompilationContext() { _container = new Lazy <IContainer>(() => new Container(services)); _graph = new Lazy <HandlerGraph>(() => { config = new GenerationConfig("Jasper.Testing.Codegen.Generated"); var container = _container.Value; config.Sources.Add(new StructureMapServices(container)); config.Assemblies.Add(typeof(IContainer).GetTypeInfo().Assembly); config.Assemblies.Add(GetType().GetTypeInfo().Assembly); var graph = new HandlerGraph(); var methods = typeof(T).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static) .Where(x => x.DeclaringType != typeof(object) && x != null && x.GetParameters().Any() && !x.IsSpecialName); foreach (var method in methods) { graph.Add(new HandlerCall(typeof(T), method)); } return(graph); }); _code = new Lazy <string>(() => Graph.GenerateCode(config)); _handlers = new Lazy <Dictionary <Type, MessageHandler> >(() => { var handlers = Graph.CompileAndBuildAll(config, _container.Value); var dict = new Dictionary <Type, MessageHandler>(); foreach (var handler in handlers) { dict.Add(handler.Chain.MessageType, handler); } return(dict); }); }
public void add_a_handler_for_a_concrete_class_creates_a_new_chain() { theGraph.Add(concreteCall); var call = theGraph.ChainFor(typeof(Input)).OfType <HandlerCall>().Single(); call.ShouldEqual(concreteCall); call.ShouldNotBeTheSameAs(concreteCall); }
public void merging_matching_chains_merges_the_handlers_for_the_same_message() { theGraph.Add(concreteCall); var other = new HandlerGraph(); other.Add(concreteCall2); other.Add(concreteCall3); theGraph.Import(other); theGraph.ShouldHaveCount(1); var chain = theGraph.ChainFor(typeof (Input)); chain.ElementAt(0).Equals(concreteCall).ShouldBeTrue(); chain.ElementAt(1).Equals(concreteCall2).ShouldBeTrue(); chain.ElementAt(2).Equals(concreteCall3).ShouldBeTrue(); }
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(); }