Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service Fabric Autofac example for AspNet DotNetCore 3.1+ #23

Open
diegosasw opened this issue Oct 9, 2020 · 4 comments
Open

Service Fabric Autofac example for AspNet DotNetCore 3.1+ #23

diegosasw opened this issue Oct 9, 2020 · 4 comments
Assignees

Comments

@diegosasw
Copy link

No examples on how to use Autofac in AspNet Core (DotNet Core 3.1+) web applications that run in Service Fabric

The repo at https://github.com/autofac/Examples/tree/master/src/ServiceFabricDemo/AutofacServiceFabricDemo hasn't been updated in 3 years. A lot has changed since then.

For instance, Startup.cs must have a void ConfigureServices(IServiceCollection services) method. Returning IServiceProvider is not valid anymore after DotNetCore 3.1+

I have created the following branch with a web app running the latest DotNetCore, that uses service fabric and Microsoft Dependency Injection. See here

It fulfills all the requirements (DI, reading appsettings, clean change of environment for testing, TestServer with possibility to overwrite DI registrations for mocks, etc.). Please feel free to have a look and if there's any way to add Autofac to that sample I'll be happy to contribute.

There are unanswered questions in StackOverflow about the same:
https://stackoverflow.com/questions/59980827/service-fabric-aspnet-core-3-1-autofac-webhostbuilder
https://stackoverflow.com/questions/64260534/how-to-use-service-fabric-service-with-aspnet-core-webapi-and-autofac-and-run-te
https://stackoverflow.com/questions/64278765/how-to-use-autofac-with-iwebhost

Desired Solution

A basic example on how to register Autofac with a WebHostBuilder (if possible), and where to register dependencies in a service fabric app would be enough.

Alternatives You've Considered

The alternative I've considered is not to use Autofac, but if I could help in any way to find out how to do it or to suggest something, I'll do that.

@diegosasw
Copy link
Author

I have here a branch feature/Autofac following the existing documentation on the web and examples.

It does not work for netcoreapp3.1, the service gets deployed in Service Fabric but unhealthy, it throws Autofac exceptions. Any help or further clarification would be much appreciated.

@alexmg alexmg self-assigned this Oct 22, 2020
@alexmg
Copy link
Member

alexmg commented Oct 22, 2020

Thanks for the links and samples @diegosasw. You're right about a lot having changed. I was holding off the latest release to see if other changes are required to support .NET Core. I'll look at your sample but can't say exactly how soon that will be.

@diegosasw
Copy link
Author

Thank you for your reply.
It's all good with DotNetCore2.1 and AspNetCore2. In case you want those samples, please feel free to get them from my repo
https://gitlab.com/sunnyatticsoftware/training/sasw-aspnetcore-testing/-/tree/master/aspnetcore2_1_autofac_servicefabric

Good luck! it doesn't look easy to me! :)

@tillig
Copy link
Member

tillig commented Jan 25, 2021

FWIW, I've updated the build for this repo to be cross-platform so whenever we get a .NET Core compatible Service Fabric demo working, we should update the build script to ensure it also builds cross-platform instead of only Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants