public void Run(IApplication appInstance)
        {
            var serviceTypeName = GetApplicationTypeName();

            ConfigureEventSource(serviceTypeName);

            try
            {
                ServiceRuntime.RegisterServiceAsync(serviceTypeName, context =>
                {
                    var baseStatelessService = new BaseStatelessService(context);
                    baseStatelessService.Initialize(appInstance);
                    return(baseStatelessService);
                })
                .GetAwaiter()
                .GetResult();

                ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, appInstance.GetType().Name);

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                Log.Fatal(e, "Unhandled exception while registering the fabric service");
                ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }
Ejemplo n.º 2
0
        // In case of multiple http/https endpoints per service in ServiceFabric
        // Please use method without 'builder' parameter
        public static void StartApplicationInFabric <TStartup>(
            this IWebHostBuilder builder,
            string serviceTypeName,
            string serviceManifestName,
            Action <IServiceCollection> configureServices,
            Func <X509Certificate2> configureEndpointCertificate = null)
            where TStartup : class
        {
            ConfigureEventSource(serviceTypeName);

            try
            {
                ServiceRuntime.RegisterServiceAsync(serviceTypeName, context =>
                {
                    var baseStatelessService = new BaseStatelessService <TStartup>(
                        builder,
                        serviceTypeName,
                        serviceManifestName,
                        context,
                        configureServices,
                        configureEndpointCertificate);

                    baseStatelessService.Initialize();
                    return(baseStatelessService);
                })
                .GetAwaiter()
                .GetResult();

                ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, serviceTypeName);

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                Logger.LogCritical(e, "Unhandled exception while registering the fabric service");
                ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }