public RestfulGrain(IDispatcher <T> dispatcher, EventStoreClient eventStore, ILogger <RestfulGrain <T> > logger, ITelemetryClient telemetry, IEventSerializer eventSerializer, IClusterClient clusterClient, UpgradeMap upgradeMap) { _dispatcher = dispatcher; _eventStore = eventStore; _logger = logger; _telemetry = telemetry; _eventSerializer = eventSerializer; _clusterClient = clusterClient; _upgradeMap = upgradeMap; }
public static IHostBuilder AddMetaflow(this IHostBuilder builder, List <Assembly> assemblies = null) { builder.UseOrleans((Microsoft.Extensions.Hosting.HostBuilderContext ctx, ISiloBuilder siloBuilder) => { var config = ctx.Configuration.GetSection("Metaflow").Get <MetaflowConfig>(); List <Assembly> metaflowAssemblies = assemblies ?? config.Assemblies.Where(a => !string.IsNullOrEmpty(a)) .Select(a => AssemblyLoadContext.Default.LoadFromAssemblyPath(Path.GetFullPath(a))).ToList(); siloBuilder .AddCustomStorageBasedLogConsistencyProviderAsDefault() .Configure <ClusterOptions>(opts => { opts.ClusterId = $"{config.ClusterName}Cluster"; opts.ServiceId = $"{config.ClusterName}Service"; }) .ConfigureApplicationParts(parts => { parts.AddApplicationPart(typeof(IRestfulGrain <>).Assembly).WithCodeGeneration(); foreach (var assembly in metaflowAssemblies) { parts.AddApplicationPart(assembly).WithCodeGeneration(); } }) .ConfigureServices(services => { services.AddScoped(typeof(IDispatcher <>), typeof(ReflectionDispatcher <>)); services.AddApplicationInsightsTelemetry(); services.AddHealthChecks(); services.AddScoped <GrainActionFilterAttribute>(); services.AddScoped <ITelemetryClient, AppInsightsTelemetryClient>(); services.AddControllers() .AddMetaflow(metaflowAssemblies); services.AddHttpClient(); services.AddSingleton <IEventSerializer, EventSerializer>(); services.AddSingleton(_ => { List <Type> types = metaflowAssemblies.SelectMany(a => a.GetExportedTypes()).ToList(); List <Type> resourceTypes = types.Where(t => t.GetCustomAttributes().Any(a => a is RestfulAttribute)).ToList(); return(UpgradeMap.Initialize(resourceTypes)); }); services.AddEventStoreClient(settings => { settings.ConnectivitySettings.Address = new Uri(config.EventStore.Endpoint); settings.DefaultCredentials = new UserCredentials(config.EventStore.User, config.EventStore.Password); settings.CreateHttpMessageHandler = () => new SocketsHttpHandler { SslOptions = { RemoteCertificateValidationCallback = delegate { return(true); } } }; }); }); if (config.Local) { siloBuilder .UseLocalhostClustering(siloPort: config.SiloPort, gatewayPort: config.GatewayPort) .Configure <EndpointOptions>(o => o.AdvertisedIPAddress = IPAddress.Loopback); } else { siloBuilder .UseAzureStorageClustering(opt => opt.ConnectionString = config.AzureStorage) .ConfigureEndpoints(siloPort: config.SiloPort, gatewayPort: config.GatewayPort); } }); return(builder); }