コード例 #1
0
        private void aspnetcore(JasperRegistry parent)
        {
            this.AddSingleton <ConnegRules>();

            this.AddScoped <IHttpContextAccessor>(x => new HttpContextAccessor());
            this.AddSingleton(parent.HttpRoutes.Routes.Router);
            this.AddSingleton(parent.HttpRoutes.Routes);
            ForSingletonOf <IUrlRegistry>().Use(parent.HttpRoutes.Routes.Router.Urls);

            this.AddSingleton <IServiceProviderFactory <IServiceCollection> >(new DefaultServiceProviderFactory());
        }
コード例 #2
0
ファイル: JasperRuntime.cs プロジェクト: brokenbot/jasper
        private static async Task <JasperRuntime> bootstrap(JasperRegistry registry)
        {
            if (registry.Logging.UseConsoleLogging)
            {
                registry.Services.AddTransient <IMessageLogger, ConsoleMessageLogger>();
                registry.Services.AddTransient <ITransportLogger, ConsoleTransportLogger>();
            }


            var timer = new PerfTimer();

            timer.Start("Bootstrapping");

            timer.Record("Finding and Applying Extensions", () => { applyExtensions(registry); });

            timer.Record("Bootstrapping Settings", () => registry.Settings.Bootstrap());


            var handlerCompilation = registry.Bus.CompileHandlers(registry, timer);


            var services = registry.CombinedServices();

            var runtime         = new JasperRuntime(registry, services, timer);
            var featureBuilding = registry.BuildFeatures(runtime, timer);

            await handlerCompilation;
            await registry.Bus.Activate(runtime, registry.Generation, timer);

            await featureBuilding;

            await registry.Startup(runtime);

            // Run environment checks
            timer.Record("Environment Checks", () =>
            {
                var recorder = EnvironmentChecker.ExecuteAll(runtime);
                if (runtime.Get <BusSettings>().ThrowOnValidationErrors)
                {
                    recorder.AssertAllSuccessful();
                }
            });

            timer.MarkStart("Register Node");
            await registerRunningNode(runtime);

            timer.MarkFinished("Register Node");

            timer.Stop();

            return(runtime);
        }
コード例 #3
0
        /// <summary>
        /// Add Jasper to an ASP.Net Core application with optional configuration to Jasper
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="overrides">Programmatically configure Jasper options</param>
        /// <param name="configure">Programmatically configure Jasper options using the application's IConfiguration and IHostingEnvironment</param>
        /// <returns></returns>
        public static IWebHostBuilder UseJasper(this IWebHostBuilder builder, Action <JasperRegistry> overrides = null, Action <WebHostBuilderContext, JasperOptions> configure = null)
        {
            var registry = new JasperRegistry(builder.GetSetting(WebHostDefaults.ApplicationKey));

            overrides?.Invoke(registry);

            if (configure != null)
            {
                registry.Settings.Messaging(configure);
            }

            return(builder.UseJasper(registry));
        }
コード例 #4
0
ファイル: CallingAssembly.cs プロジェクト: kassadube/jasper
        public static Assembly DetermineApplicationAssembly(JasperRegistry registry)
        {
            var assembly  = registry.GetType().GetAssembly();
            var isFeature = assembly.GetCustomAttribute <JasperFeatureAttribute>() != null;

            if (!Equals(assembly, typeof(JasperRegistry).GetAssembly()) && !isFeature)
            {
                return(assembly);
            }
            else
            {
                return(CallingAssembly.Find());
            }
        }
コード例 #5
0
ファイル: JasperRuntime.cs プロジェクト: hannanmumtaz/jasper
        private JasperRuntime(JasperRegistry registry, PerfTimer timer)
        {
            Bootstrapping = timer;


            registry.CodeGeneration.Sources.Add(new NowTimeVariableSource());

            registry.CodeGeneration.Assemblies.Add(GetType().GetTypeInfo().Assembly);
            registry.CodeGeneration.Assemblies.Add(registry.ApplicationAssembly);

            Registry = registry;

            _bus = new Lazy <IMessageContext>(Get <IMessageContext>);
        }
コード例 #6
0
        private void conneg(JasperRegistry parent)
        {
            this.AddOptions();

            var forwarding = new Forwarders();

            For <Forwarders>().Use(forwarding);

            Scan(_ =>
            {
                _.Assembly(parent.ApplicationAssembly);
                _.AddAllTypesOf <IMessageSerializer>();
                _.AddAllTypesOf <IMessageDeserializer>();
                _.With(new ForwardingRegistration(forwarding));
            });
        }
コード例 #7
0
        private static void applyExtensions(JasperRegistry registry)
        {
            var assemblies = FindExtensionAssemblies();

            if (!assemblies.Any())
            {
                return;
            }

            var extensions = assemblies
                             .Select(x => x.GetAttribute <JasperModuleAttribute>().ExtensionType)
                             .Where(x => x != null)
                             .Select(x => TypeExtensions.As <IJasperExtension>(Activator.CreateInstance(x)))
                             .ToArray();

            registry.ApplyExtensions(extensions);
        }
コード例 #8
0
        private void messaging(JasperRegistry parent)
        {
            ForSingletonOf <MessagingSerializationGraph>().Use <MessagingSerializationGraph>();

            For <IEnvelopePersistor>().Use <NulloEnvelopePersistor>();
            this.AddSingleton <InMemorySagaPersistor>();

            this.AddSingleton(parent.Messaging.Graph);
            this.AddSingleton <IChannelGraph>(parent.Messaging.Channels);
            this.AddSingleton <ILocalWorkerSender>(parent.Messaging.LocalWorker);

            this.AddSingleton <IRetries, EnvelopeRetries>();

            For <ITransport>()
            .Use <LoopbackTransport>();

            For <ITransport>()
            .Use <TcpTransport>();


            ForSingletonOf <IMessagingRoot>().Use <MessagingRoot>();

            ForSingletonOf <ObjectPoolProvider>().Use(new DefaultObjectPoolProvider());



            MessagingRootService(x => x.Workers);
            MessagingRootService(x => x.Pipeline);

            MessagingRootService(x => x.Router);
            MessagingRootService(x => x.Lookup);
            MessagingRootService(x => x.ScheduledJobs);

            For <IMessageContext>().Use(new MessageContextInstance());

            ForSingletonOf <ITransportLogger>().Use <TransportLogger>();

            ForSingletonOf <INodeDiscovery>().UseIfNone(new InMemoryNodeDiscovery(parent.MessagingSettings));
            ForSingletonOf <ISubscriptionsRepository>().UseIfNone <DefaultSubscriptionsRepository>();


            For <IUriLookup>().Use <ConfigUriLookup>();

            For <IEnvironmentRecorder>().Use <EnvironmentRecorder>();
        }
コード例 #9
0
ファイル: JasperRuntime.cs プロジェクト: kassadube/jasper
        private static void applyExtensions(JasperRegistry registry)
        {
            var assemblies = AssemblyFinder
                             .FindAssemblies(a => a.HasAttribute <JasperModuleAttribute>())
                             .ToArray();

            if (!assemblies.Any())
            {
                return;
            }

            var extensions = assemblies
                             .Select(x => x.GetAttribute <JasperModuleAttribute>().ExtensionType)
                             .Select(x => Activator.CreateInstance(x).As <IJasperExtension>())
                             .ToArray();

            registry.ApplyExtensions(extensions);
        }
コード例 #10
0
        private static async Task applyExtensions(JasperRegistry registry, IEnumerable <Assembly> assemblies)
        {
            if (!assemblies.Any())
            {
                return;
            }

            Func <Type, bool> filter = type => type.CanBeCastTo <IJasperExtension>() && type.IsConcreteWithDefaultCtor();

            var extensionTypes = await TypeRepository.FindTypes(assemblies,
                                                                TypeClassification.Concretes | TypeClassification.Closed, filter).ConfigureAwait(false);

            foreach (var extensionType in extensionTypes)
            {
                var extension = Activator.CreateInstance(extensionType).As <IJasperExtension>();
                extension.Configure(registry);
            }
        }
コード例 #11
0
        private static async Task <JasperRuntime> bootstrap(JasperRegistry registry)
        {
            applyExtensions(registry);

            registry.Settings.Bootstrap();

            var features = registry.Features;

            var serviceRegistries = await Task.WhenAll(features.Select(x => x.Bootstrap(registry)))
                                    .ConfigureAwait(false);

            var collections = new List <IServiceCollection>();

            collections.AddRange(serviceRegistries);
            collections.Add(registry.ExtensionServices);
            collections.Add(registry.Services);


            var services = await ServiceCollectionExtensions.Combine(collections.ToArray());

            registry.Generation.ReadServices(services);


            var runtime = new JasperRuntime(registry, services);

            registry.Http.As <IWebHostBuilder>().UseSetting(WebHostDefaults.ApplicationKey, registry.ApplicationAssembly.FullName);

            runtime.HttpAddresses = registry.Http.As <IWebHostBuilder>().GetSetting(WebHostDefaults.ServerUrlsKey);

            await Task.WhenAll(features.Select(x => x.Activate(runtime, registry.Generation)))
            .ConfigureAwait(false);

            // Run environment checks
            var recorder = EnvironmentChecker.ExecuteAll(runtime);

            if (runtime.Get <BusSettings>().ThrowOnValidationErrors)
            {
                recorder.AssertAllSuccessful();
            }

            await registerRunningNode(runtime);

            return(runtime);
        }
コード例 #12
0
        private void messaging(JasperRegistry parent)
        {
            this.AddSingleton(parent.Bus.Graph);
            this.AddSingleton <IChannelGraph>(parent.Bus.Channels);
            this.AddSingleton <ILocalWorkerSender>(parent.Bus.LocalWorker);


            For <ITransport>()
            .Use <LoopbackTransport>();

            For <ITransport>()
            .Use <TcpTransport>();



            ForSingletonOf <MessagingRoot>().Use <MessagingRoot>();

            ForSingletonOf <ObjectPoolProvider>().Use(new DefaultObjectPoolProvider());

            this.AddSingleton <IWorkerQueue>(s => s.GetService <MessagingRoot>().Workers);
            this.AddSingleton(s => s.GetService <MessagingRoot>().Pipeline);
            this.AddSingleton(s => s.GetService <MessagingRoot>().Serialization);
            this.AddTransient(s => s.GetService <MessagingRoot>().Build());
            this.AddSingleton(s => s.GetService <MessagingRoot>().Logger);
            this.AddSingleton(s => s.GetService <MessagingRoot>().Router);
            this.AddSingleton(s => s.GetService <MessagingRoot>().Lookup);
            this.AddSingleton(s => s.GetService <MessagingRoot>().ScheduledJobs);


            ForSingletonOf <CompositeTransportLogger>().Use <CompositeTransportLogger>();

            ForSingletonOf <INodeDiscovery>().UseIfNone(new InMemoryNodeDiscovery(parent.BusSettings));
            ForSingletonOf <ISubscriptionsRepository>().UseIfNone(new InMemorySubscriptionsRepository());


            For <IUriLookup>().Use <ConfigUriLookup>();


            For <IPersistence>().Use <NulloPersistence>();

            For <IEnvironmentRecorder>().Use <EnvironmentRecorder>();
        }
コード例 #13
0
        private JasperRuntime(JasperRegistry registry, Registry[] serviceRegistries)
        {
            Container = new Container(_ =>
            {
                _.AddRegistry(registry.Services);
                foreach (var serviceRegistry in serviceRegistries)
                {
                    _.AddRegistry(serviceRegistry);
                }
            })
            {
                DisposalLock = DisposalLock.Ignore
            };

            registry.Generation.Sources.Add(new StructureMapServices(Container));
            registry.Generation.Assemblies.Add(GetType().GetTypeInfo().Assembly);
            registry.Generation.Assemblies.Add(registry.ApplicationAssembly);

            _registry = registry;
        }
コード例 #14
0
        public JasperServiceRegistry(JasperRegistry parent)
        {
            For <IMetrics>().Use <NulloMetrics>();
            For <IHostedService>().Use <MetricsCollector>();

            this.AddLogging();

            For <IMessageLogger>().Use <MessageLogger>().Singleton();
            For <ITransportLogger>().Use <TransportLogger>().Singleton();


            this.AddSingleton(parent.CodeGeneration);

            For <IHostedService>().Use <NodeRegistration>();
            For <IHostedService>().Use <BackPressureAgent>();

            conneg(parent);
            messaging(parent);

            aspnetcore(parent);
        }
コード例 #15
0
        private static async Task <JasperRuntime> bootstrap(JasperRegistry registry)
        {
            /*
             * Questions:
             * Pre-load settings that we know we're looking for?
             *
             *
             * 1. Look for extensions
             * 2. Apply all extensions
             * 3. Do all the necessary Settings stuff
             * 4. Activate each feature in parallel
             * 5. Apply services
             * 6. Activate each in parallel
             *
             *
             *
             */

            var assemblies = AssemblyFinder.FindAssemblies(a => a.HasAttribute <JasperModuleAttribute>());


            await applyExtensions(registry, assemblies).ConfigureAwait(false);

            registry.Settings.Bootstrap();

            var features = registry.Features;

            var serviceRegistries = await Task.WhenAll(features.Select(x => x.Bootstrap(registry)))
                                    .ConfigureAwait(false);

            var runtime = new JasperRuntime(registry, serviceRegistries);


            await Task.WhenAll(features.Select(x => x.Activate(runtime, registry.Generation)))
            .ConfigureAwait(false);

            return(runtime);
        }
コード例 #16
0
ファイル: JasperRuntime.cs プロジェクト: kassadube/jasper
        private JasperRuntime(JasperRegistry registry, IServiceCollection services)
        {
            services.AddSingleton(this);

            Services = services.ToImmutableArray();

            Container = new Container(_ =>
            {
                _.Populate(services);
            })
            {
                DisposalLock = DisposalLock.Ignore
            };

            registry.Generation.Sources.Add(new NowTimeVariableSource());

            registry.Generation.Assemblies.Add(GetType().GetTypeInfo().Assembly);
            registry.Generation.Assemblies.Add(registry.ApplicationAssembly);

            _registry = registry;

            _bus = new Lazy <IServiceBus>(Get <IServiceBus>);
        }
コード例 #17
0
        private void messaging(JasperRegistry parent)
        {
            ForSingletonOf <MessagingSerializationGraph>().Use <MessagingSerializationGraph>();

            For <IEnvelopePersistor>().Use <NulloEnvelopePersistor>();
            this.AddSingleton <InMemorySagaPersistor>();

            this.AddSingleton(parent.Messaging.Graph);
            this.AddSingleton <ISubscriberGraph>(parent.Messaging.Subscribers);
            this.AddSingleton <ILocalWorkerSender>(parent.Messaging.LocalWorker);

            this.AddSingleton <IRetries, EnvelopeRetries>();

            For <ITransport>()
            .Use <LoopbackTransport>();

            For <ITransport>()
            .Use <TcpTransport>();


            ForSingletonOf <IMessagingRoot>().Use <MessagingRoot>();

            ForSingletonOf <ObjectPoolProvider>().Use(new DefaultObjectPoolProvider());


            MessagingRootService(x => x.Workers);
            MessagingRootService(x => x.Pipeline);

            MessagingRootService(x => x.Router);
            MessagingRootService(x => x.ScheduledJobs);

            For <IMessageContext>().Use(new MessageContextInstance());

            ForSingletonOf <ITransportLogger>().Use <TransportLogger>();

            For <IEnvironmentRecorder>().Use <EnvironmentRecorder>();
        }
コード例 #18
0
        private static async Task <JasperRuntime> bootstrap(JasperRegistry registry)
        {
            applyExtensions(registry);

            registry.Settings.Bootstrap();

            var features = registry.Features;

            var serviceRegistries = await Task.WhenAll(features.Select(x => x.Bootstrap(registry)))
                                    .ConfigureAwait(false);

            var collections = new List <IServiceCollection>();

            collections.AddRange(serviceRegistries);
            collections.Add(registry.ExtensionServices);
            collections.Add(registry.Services);


            var services = await ServiceCollectionExtensions.Combine(collections.ToArray());

            registry.Generation.ReadServices(services);


            var runtime = new JasperRuntime(registry, services);


            await Task.WhenAll(features.Select(x => x.Activate(runtime, registry.Generation)))
            .ConfigureAwait(false);

            // TODO -- THIS IS TEMPORARY UNTIL WE DO GH-212
            var hostedServices = runtime.Container.GetAllInstances <IHostedService>()
                                 .Select(x => x.StartAsync(CancellationToken.None));

            await Task.WhenAll(hostedServices);

            return(runtime);
        }
コード例 #19
0
ファイル: JasperRuntime.cs プロジェクト: brokenbot/jasper
        private JasperRuntime(JasperRegistry registry, IServiceCollection services, PerfTimer timer)
        {
            Bootstrapping = timer;

            services.AddSingleton(this);

            timer.Record("new Container()", () =>
            {
                Container = new Container(services, timer)
                {
                    DisposalLock = DisposalLock.Ignore
                };
            });


            registry.Generation.Sources.Add(new NowTimeVariableSource());

            registry.Generation.Assemblies.Add(GetType().GetTypeInfo().Assembly);
            registry.Generation.Assemblies.Add(registry.ApplicationAssembly);

            Registry = registry;

            _bus = new Lazy <IServiceBus>(Get <IServiceBus>);
        }
コード例 #20
0
ファイル: JasperRuntime.cs プロジェクト: rvanderplaat/jasper
 /// <summary>
 ///     Builds and initializes a JasperRuntime for the registry
 /// </summary>
 /// <param name="registry"></param>
 /// <returns></returns>
 public static Task <JasperRuntime> ForAsync(JasperRegistry registry)
 {
     return(bootstrap(registry));
 }
コード例 #21
0
ファイル: JasperRuntime.cs プロジェクト: kassadube/jasper
 public static JasperRuntime For(JasperRegistry registry)
 {
     return(bootstrap(registry).GetAwaiter().GetResult());
 }
コード例 #22
0
        private static async Task <JasperRuntime> bootstrap(JasperRegistry registry)
        {
            var timer = new PerfTimer();

            timer.Start("Bootstrapping");

            timer.Record("Finding and Applying Extensions", () =>
            {
                applyExtensions(registry);
            });

            var buildingServices = Task.Factory.StartNew(() =>
            {
                return(timer.Record("Combining Services and Building Settings", registry.CompileConfigurationAndServicesForIdiomaticBootstrapping));
            });



            var handlerCompilation = registry.Messaging.CompileHandlers(registry, timer);


            var runtime = new JasperRuntime(registry, timer);

            var services = await buildingServices;

            services.AddSingleton(runtime);


            var container = await Lamar.Container.BuildAsync(services, timer);

            container.DisposalLock = DisposalLock.Ignore;
            runtime.Container      = container;


            var routeDiscovery = registry.HttpRoutes.Enabled
                ? registry.HttpRoutes.FindRoutes(runtime, registry, timer)
                : Task.CompletedTask;

            runtime.buildAspNetCoreServer(services);

            await routeDiscovery;

            await Task.WhenAll(runtime.startAspNetCoreServer(), handlerCompilation, runtime.startHostedServices());


            // Run environment checks
            timer.Record("Environment Checks", () =>
            {
                var recorder = EnvironmentChecker.ExecuteAll(runtime);
                if (runtime.Settings.ThrowOnValidationErrors)
                {
                    recorder.AssertAllSuccessful();
                }
            });

            _lifetime = TypeExtensions.As <ApplicationLifetime>(container.GetInstance <IApplicationLifetime>());
            _lifetime.NotifyStarted();

            timer.Stop();

            return(runtime);
        }
コード例 #23
0
ファイル: JasperRegistry.cs プロジェクト: randommuses/jasper
 public Logging(JasperRegistry parent)
 {
     _parent = parent;
 }
コード例 #24
0
ファイル: JasperRuntime.cs プロジェクト: rvanderplaat/jasper
 /// <summary>
 ///     Builds and initializes a JasperRuntime for the registry
 /// </summary>
 /// <param name="registry"></param>
 /// <returns></returns>
 public static JasperRuntime For(JasperRegistry registry)
 {
     return(ForAsync(registry).GetAwaiter().GetResult());
 }