Example #1
0
        /// <summary>
        /// Configure the container to use Orleans, including the default silo name & services.
        /// </summary>
        /// <param name="builder">The host builder.</param>
        /// <param name="siloName">The name to use for this silo</param>
        /// <param name="configureOptions">The delegate that configures the options using the options builder.</param>
        /// <returns>The host builder.</returns>
        public static ISiloHostBuilder Configure(this ISiloHostBuilder builder, string siloName, Action <OptionsBuilder <ClusterOptions> > configureOptions = null)
        {
            builder.ConfigureServices((context, services) =>
            {
                if (!context.Properties.ContainsKey("OrleansServicesAdded"))
                {
                    services.PostConfigure <SiloOptions>(options => options.SiloName = options.SiloName
                                                                                       ?? context.HostingEnvironment.ApplicationName
                                                                                       ?? $"Silo_{Guid.NewGuid().ToString("N").Substring(0, 5)}");

                    services.TryAddSingleton <Silo>();
                    DefaultSiloServices.AddDefaultServices(context, services);

                    context.Properties.Add("OrleansServicesAdded", true);
                }

                if (!string.IsNullOrEmpty(siloName))
                {
                    builder.ConfigureSiloName(siloName);
                }

                configureOptions?.Invoke(services.AddOptions <ClusterOptions>());
            });
            return(builder);
        }
        /// <summary>
        /// Configure the container to use Orleans.
        /// </summary>
        /// <param name="builder">The silo builder.</param>
        /// <returns>The silo builder.</returns>
        public static ISiloBuilder ConfigureDefaults(this ISiloBuilder builder)
        {
            return(builder.ConfigureServices((context, services) =>
            {
                if (!context.Properties.ContainsKey("OrleansServicesAdded"))
                {
                    services.PostConfigure <SiloOptions>(
                        options => options.SiloName =
                            options.SiloName ?? $"Silo_{Guid.NewGuid().ToString("N").Substring(0, 5)}");

                    services.TryAddSingleton <Silo>();
                    DefaultSiloServices.AddDefaultServices(services);

                    context.Properties.Add("OrleansServicesAdded", true);
                }
            }));
        }
Example #3
0
        /// <summary>
        /// Configure the container to use Orleans, including the default silo name & services.
        /// </summary>
        /// <param name="builder">The host builder.</param>
        /// <returns>The host builder.</returns>
        public static ISiloHostBuilder ConfigureOrleans(this ISiloHostBuilder builder)
        {
            builder.ConfigureServices((context, services) =>
            {
                if (!context.Properties.ContainsKey("OrleansServicesAdded"))
                {
                    services.PostConfigure <SiloIdentityOptions>(options => options.SiloName = options.SiloName
                                                                                               ?? context.HostingEnvironment.ApplicationName
                                                                                               ?? $"Silo_{Guid.NewGuid().ToString("N").Substring(0, 5)}");

                    services.TryAddSingleton <Silo>(sp => new Silo(sp.GetRequiredService <SiloInitializationParameters>(), sp));
                    DefaultSiloServices.AddDefaultServices(context, services);

                    context.Properties.Add("OrleansServicesAdded", true);
                }
            });
            return(builder);
        }
Example #4
0
 public SiloBuilder(IServiceCollection services)
 {
     DefaultSiloServices.AddDefaultServices(services);
     Services = services;
 }