Exemple #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            //Configure Jane
            JaneConfiguration.Create();

            //Config Exceptionless
            if (!JaneConfiguration.Instance.Root["Exceptionless:ApiKey"].IsNullOrEmpty())
            {
                services.AddExceptionless(config => config.ReadFromConfiguration(JaneConfiguration.Instance.Root));
            }

            services.AddJaneAspNetCore();

            //Compression
            services.AddResponseCompression();

            //Configure CORS for application
            services.AddCorsPolicy(JaneConfiguration.Instance.Root);

            services.AddControllers()
            .AddJaneJsonOptions();

            //Configure Auth
            services
            .AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .ConfigureJwtBearer(JaneConfiguration.Instance.Root);

            //Swagger
            services.AddSwaggerGen(options => { options.SetupSwaggerGenOptions(JaneConfiguration.Instance.Root); });
        }
Exemple #2
0
        private void InitializeENode()
        {
            JaneConfiguration.Create();

            var services = new ServiceCollection();

            ConfigureService(services);

            var serviceProviderFactory = new AutofacServiceProviderFactory();
            var containerBuilder       = serviceProviderFactory.CreateBuilder(services);

            ConfigureContainer(containerBuilder);

            var serviceProvider = serviceProviderFactory.CreateServiceProvider(containerBuilder);

            serviceProvider.PopulateJaneENodeDIContainer();

            JaneConfiguration.Instance.CreateAutoMapperMappings();
            JaneConfiguration.Instance.RegisterBackgroundJob(_bussinessAssemblies);

            ENodeConfiguration.Instance.InitializeBusinessAssemblies(_bussinessAssemblies);

            var enodeConfig = ObjectContainer.Resolve <IENodeConfiguration>();

            ENodeConfiguration.Instance
            .InitializeRedisLockService(new RedisOptions()
            {
                ConnectionString = enodeConfig.LockServiceConnectionString,
                DatabaseId       = enodeConfig.LockServiceDatabaseId
            },
                                        "RedisLockPrefix")
            .InitializeMongoDbEventStore(new ENode.Configurations.MongoDbConfiguration()
            {
                ConnectionString = enodeConfig.EventStoreConnectionString,
                DatabaseName     = enodeConfig.EventStoreDatabaseName
            },
                                         "BoundedContextEventStream")
            .InitializeMongoDbPublishedVersionStore(new ENode.Configurations.MongoDbConfiguration()
            {
                ConnectionString = enodeConfig.EventStoreConnectionString,
                DatabaseName     = enodeConfig.EventStoreDatabaseName
            },
                                                    "BoundedContextPublishedVersion")
            .InitializeMySqlAggregateSnapshotter(
                enodeConfig.AggregateSnapshotConnectionString,
                "BoundedContextAggregateSnapshot"
                )
            .StartKafka()
            .Start();
        }
Exemple #3
0
        public static async Task Main(string[] args)
        {
            var bussinessAssemblies = new[]
            {
                Assembly.Load("BoundedContext.CommandHandlers"),
                Assembly.Load("BoundedContext.Commands"),
                Assembly.Load("BoundedContext.Domain"),
                Assembly.Load("BoundedContext.Messages"),
                Assembly.Load("BoundedContext.Repositories.MongoDb"),
                Assembly.Load("BoundedContext.ReadModel"),
                Assembly.Load("BoundedContext.QueryServices"),
                Assembly.Load("BoundedContext.ProcessManagers"),
                Assembly.Load("BoundedContext.MessagePublishers"),
                Assembly.Load("BoundedContext.BackgroundJobs"),
                Assembly.GetExecutingAssembly()
            };

            var autoMapperConfigurationAssemblies = new[]
            {
                Assembly.Load("BoundedContext.CommandHandlers"),
                Assembly.Load("BoundedContext.QueryServices"),
                Assembly.Load("BoundedContext.ReadModel"),
                Assembly.Load("BoundedContext.MessagePublishers")
            };

            var host = new HostBuilder()
                       .UseServiceProviderFactory(new AutofacServiceProviderFactory())
                       .ConfigureServices(services =>
            {
                JaneConfiguration.Create();

                services.AddHostedService <HostedService>();
            })
                       .ConfigureContainer <ContainerBuilder>((context, builder) =>
            {
                JaneConfiguration.Instance
                .UseAutofac(builder)
                .RegisterCommonComponents()
                .RegisterAssemblies(bussinessAssemblies)
                .UseLog4Net()
                .UseClockProvider(ClockProviders.Utc)
                .UseAutoMapper(autoMapperConfigurationAssemblies)
                .UseMongoDb(() =>
                {
                    var pack = new ConventionPack
                    {
                        new EnumRepresentationConvention(BsonType.String)
                    };
                    ConventionRegistry.Register("EnumStringConvention", pack, t => true);
                    BsonSerializer.RegisterSerializer(typeof(Dictionary <string, object>), new ObjectDictionarySerializer());
                    BsonSerializer.RegisterSerializer(typeof(decimal), new DecimalSerializer(BsonType.Decimal128));
                    BsonSerializer.RegisterSerializer(typeof(decimal?), new NullableSerializer <decimal>(new DecimalSerializer(BsonType.Decimal128)));
                })
                .UseRedis()
                .LoadKafkaConfiguration()
                .LoadENodeConfiguration()
                .RegisterUnhandledExceptionHandler()
                .CreateECommon(builder)
                .CreateENode(new ConfigurationSetting()
                {
                    AggregateRootMaxInactiveSeconds     = 3600 * 1,
                    EventMailBoxPersistenceMaxBatchSize = 500
                })
                .RegisterENodeComponents()
                .RegisterBusinessComponents(bussinessAssemblies)
                .UseRedisLockService()
                .UseMongoDbEventStore()
                .UseMongoDbPublishedVersionStore()
                .UseMySqlAggregateSnapshotter()
                .UseKafka();
            })
                       .Build();

            host.Services.PopulateJaneENodeDIContainer();

            JaneConfiguration.Instance.CreateAutoMapperMappings();

            ENodeConfiguration.Instance
            .InitializeBusinessAssemblies(bussinessAssemblies);

            var enodeConfig = ObjectContainer.Resolve <IENodeConfiguration>();

            ENodeConfiguration.Instance
            .InitializeRedisLockService(new RedisOptions()
            {
                ConnectionString = enodeConfig.LockServiceConnectionString,
                DatabaseId       = enodeConfig.LockServiceDatabaseId
            },
                                        "RedisLockPrefix")
            .InitializeMongoDbEventStore(new ENode.Configurations.MongoDbConfiguration()
            {
                ConnectionString = enodeConfig.EventStoreConnectionString,
                DatabaseName     = enodeConfig.EventStoreDatabaseName
            },
                                         "BoundedContextEventStream")
            .InitializeMongoDbPublishedVersionStore(new ENode.Configurations.MongoDbConfiguration()
            {
                ConnectionString = enodeConfig.EventStoreConnectionString,
                DatabaseName     = enodeConfig.EventStoreDatabaseName
            },
                                                    "BoundedContextPublishedVersion")
            .InitializeMySqlAggregateSnapshotter(
                enodeConfig.AggregateSnapshotConnectionString,
                "BoundedContextAggregateSnapshot"
                );

            //Config Exceptionless
            if (JaneEnvironment.IsProduction() && !JaneConfiguration.Instance.Root["Exceptionless:ApiKey"].IsNullOrEmpty())
            {
                ExceptionlessClient.Default.Configuration.ApiKey    = JaneConfiguration.Instance.Root["Exceptionless:ApiKey"];
                ExceptionlessClient.Default.Configuration.ServerUrl = JaneConfiguration.Instance.Root["Exceptionless:ServerUrl"];
            }

            using (host)
            {
                await host.StartAsync();

                await host.WaitForShutdownAsync();
            }
        }