microsoft / service-fabric-aspnetcore

This repo contains ASP.NET Core integration for Service Fabric Reliable Services.
Other
153 stars 50 forks source link

Integrate with generic host (IHost interface) in asp.net core 2.1 #48

Open chuanboz opened 6 years ago

chuanboz commented 6 years ago

asp.net core is refactor with generic host in https://github.com/aspnet/Hosting/issues/1163 that has better support on DI and lifecycle management etc, but I do not see an integration for the ServiceFabric-AspnetCore.

the ask is to provide a ServiceFabricHost that implement IHost interface, to wrap the generic logic to register service type and also creating service instance.

here are specific difference for Service Fabric that deserve its own ServiceFabricHost:

  1. different dependency scope of service instance level.
    • Host scope (Singleton) -- Service instance scope (* unique for Service Fabric) ---Request scope ----Transient scope
  2. different execution and lifecycle for IHostedService. for regular console host, the IHostedService shall be started right after host start; but for Service Fabric, it shall be registered with service factory and won't start the IHostedService directly; All IHostedService will be started as part of ICommunicationListener.OpenAsync; and IHostedService could be started multiple times within the same process, each time whenever there is a new service instance created.

here are sample scenario usage:

public static class ServiceFabricHostBuilderExtension
    {
        public static IHostBuilder UseServiceFabricHost(this IHostBuilder hostBuilder, string ServiceTypeName);

        public static IHostBuilder ConfigureWebHost(this IHostBuilder hostBuilder, Action<HostBuilderContext, IWebHostBuilder> configureWebHost);
    }

/// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            var builder = new HostBuilder();

            // required, register service factory with ServiceFabricHost
            builder.UseServiceFabricHost("TestHttpServiceType");

            // config WebHost
            builder.ConfigureWebHost((context, webHostBuilder) => // the same native Startup experience from WebHost
                    webHostBuilder
                    .UseKestrel() // config to use Kestrel or HttpSys
                    .UseStartup<Startup>() // further extension with standard asp.net core Startup extension.
                );

            // optional, standard DI injection, injection here will be used in both host and service instance
            builder.ConfigureServices(sc => { });
            builder.ConfigureAppConfiguration(sc => { }); // configuration that will be applied to service instance.
            builder.ConfigureLogging(loggingBuilder => { }); // optional to config additional logging.

            // required, run the service until cancelled or aborted
            builder.Build().Run();
        }
Leon99 commented 4 years ago

@vturecek, @amanbha - is it possible to get an official view on switching to IHost? IWebHost is deprecated and we're not sure if it's worth using this library as this issue has been around for more than 2 years now with no promises in sight.

diegosasw commented 4 years ago

I found this old but still open issue and I wonder if it's related with the problems I'm having to get Autofac in an AspNet Core 3.1 application working for service fabric and Test Support, as I asked here.

Can I ask you guys how do you use the TestServer with an aspnet core project that runs in Service Fabric when there is such a difference in the way the Program.cs and Startup.cs work?

mezzo1981 commented 3 years ago

something new on GenericHost with ServiceFabric?

shessane commented 3 years ago

Hi all, Any update on this ?

craftyhouse commented 3 years ago

Just noting we discussed briefly on community call 51, still need to get work booked to get this completed. Will update when we get something committed.

IvanAlekseev commented 3 years ago

Is there any update on this? xAv

mezzo81 commented 3 years ago

is that completely ignored here?

mezzo81 commented 3 years ago

Just noting we discussed briefly on community call 51, still need to get work booked to get this completed. Will update when we get something committed.

since 18 Feb no update? :-(

ThiemeNL commented 3 years ago

I noticed that recently a pull request #96 was merged into the develop branch, which enables the support of the IHost.

PavanKunapareddyMSFT commented 3 years ago

Hi @ThiemeNL and everyone, We are taking a two step approach to implement this workitem 1) Enable users to use IHostBuilder/IHost interfaces to build service fabric aspnet services With this the current developer experience remains almost the same except that they could now use GenericHost instead of WebHost to build a communication listener 2) Define a new host implementation for service fabric We are currently working on the design and would be updating the thread with the proposal in few days

darthrcf commented 2 years ago

Been almost a month and release of .net 6 has been out about a week now and I noticed PR 96 as well. Any updates?

This may not be the right place for this, but are there any plans for a Service Fabric Template for .net 6 hosting Blazor Web Assembly for Visual Studio 2022?

markrendle commented 2 years ago

@PavanKunapareddyMSFT When do you expect to release an updated Microsoft.ServiceFabric.AspNetCore.Kestrel package with the IHost support?

juho-hanhimaki commented 2 years ago

Generic host support seems to be included in the latest version libraries (5.2.1363). Not mentioned in release notes though.

strat-alex commented 2 years ago

@PavanKunapareddyMSFT Would you be able to give us an update on:

  1. Define a new host implementation for service fabric We are currently working on the design and would be updating the thread with the proposal in few days

please?

shessane commented 3 months ago

It's now supported starting v5.2.1363 of Microsoft.ServiceFabric.AspNetCore.Kestrel : https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-services-communication-aspnetcore#ihost-and-minimal-hosting-integration