Example #1
0
        public ServiceFabricHostedService(
            IServiceProvider serviceProvider,
            ReliableServiceFabricRegistrationOptions registrationOptions,
            ILogger <ServiceFabricHostedService> logger)
        {
            _statelessServiceFactory    = serviceProvider.GetService <IStatelessServiceCreatorFactory>();
            _statefulServiceFactory     = serviceProvider.GetService <IStatefulServiceCreatorFactory>();
            _addServiceContextToLogging = serviceProvider.GetService <Action <ServiceContext> >();
            _registrationOptions        = registrationOptions;
            _logger = logger;

            if (string.IsNullOrEmpty(registrationOptions.ServiceTypeName))
            {
                throw new Exception("Service Fabric service must have a ServiceTypeName set on the ServiceFabricRegistrationOptions.");
            }
        }
Example #2
0
        public static IHostBuilder UseServiceFabricStatefulServiceFactory(this IHostBuilder hostBuilder, string serviceTypeName, Func <StatefulServiceContext, StatefulService> serviceFactory, ReliableServiceFabricRegistrationOptions options = null)
        {
            options = options ?? new ReliableServiceFabricRegistrationOptions {
                ServiceTypeName = serviceTypeName
            };

            return(hostBuilder.ConfigureServices(services =>
            {
                services.AddSingleton(options);
                services.AddSingleton(serviceFactory);
                services.AddSingleton <IStatefulServiceCreatorFactory, StatefulServiceFactory>();
                services.AddHostedService <ServiceFabricHostedService>();
            }));
        }
Example #3
0
        public static IHostBuilder UseServiceFabricStatelessServiceFactory <TStatelessServiceFactory>(this IHostBuilder hostBuilder, string serviceTypeName, ReliableServiceFabricRegistrationOptions options = null)
            where TStatelessServiceFactory : class, IStatelessServiceCreatorFactory
        {
            options = options ?? new ReliableServiceFabricRegistrationOptions {
                ServiceTypeName = serviceTypeName
            };

            return(hostBuilder.ConfigureServices(services =>
            {
                services.AddSingleton(options);
                services.AddSingleton <IStatelessServiceCreatorFactory, TStatelessServiceFactory>();
                services.AddHostedService <ServiceFabricHostedService>();
            }));
        }