Example #1
0
        public static ISiloHostBuilder OrleansSelfhost(this ISiloHostBuilder hostBuilder, IConfigurationRoot configuration)
        {
            return(hostBuilder
                   .UseLocalhostClustering()
                   .ConfigureServices(services =>
            {
                services.AddOperations(typeof(CreateTenantAdapter).Assembly);
                services.AddOperations(typeof(PublishAdapter).Assembly);

                services.AddTransient <ITracer>(sp => GlobalTracer.Instance);

                services.AddSingleton <IInterpreterAsync>(sp => new LiveInterpreterAsync(sp));
                services.AddTransient <IExecutionContext, LiveExecutionContext>();
                services.AddStreamProviderRefs(typeof(RedisStreamProvider).Assembly);
                services.AddDbContext <StackUnderflowContext>(options =>
                {
                    options.UseSqlServer(
                        configuration.GetConnectionString("StackUnderflow"),
                        options =>
                    {
                        options.EnableRetryOnFailure(maxRetryCount: 10,
                                                     maxRetryDelay: TimeSpan.FromSeconds(30), null);
                    });
                });
                services.AddDbContext <UserDbContext>(options =>
                {
                    options.UseSqlServer(
                        configuration.GetConnectionString("StackUnderflow"),
                        options =>
                    {
                        options.EnableRetryOnFailure(maxRetryCount: 10,
                                                     maxRetryDelay: TimeSpan.FromSeconds(30), null);
                    });
                });

                services.AddTransient <Port <StackUnderflowContext> >(StackUnderflowContext.Factory);
                services.AddTransient <Port <UserDbContext> >(sp =>
                {
                    var grainActivationContext = sp.GetService <IGrainActivationContext>();
                    var userGrainId = UserGrainId.FromString(grainActivationContext.GrainIdentity.PrimaryKeyString);
                    return UserDbContext.DbContextFactory(sp, userGrainId.UserId.ToString());
                });
            })
                   .AddIncomingGrainCallFilter <OpenTracingInterceptor>()
                   .ConfigureApplicationParts(parts =>
            {
                parts.AddApplicationPart(typeof(BackofficeGrain).Assembly).WithReferences()
                .WithCodeGeneration();
            })
                   .AddRedisStreams("RedisProvider",
                                    c => c.ConfigureRedis(options => options.ConnectionString = configuration.GetConnectionString("RedisConnectionString")))
                   .AddMemoryGrainStorage("PubSubStore")
                   .ConfigureLogging(builder =>
            {
                builder.AddConsole();
            })
                   .AddStartupTask <StartupTask>());
        }