Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Using the same Startup.cs from a framework library for multiple Web Applications

$
0
0

We have a common Class Library Project which contains the Startup.cs and some of the common middle wares used across all the Applications(ASP .Net Core Web Applications which are dependent on the common Class library).

Th Startup.cs adds these common middle wares to the application's request pipeline and also registers the common framework Services to the IServiceCollection.

Each of the Web Application projects define their own Controllers. We want to use this same Startup.cs from all our applications.

Now, there are two issues we are encountering

            services.AddMvc().AddApplicationPart(AssemblyHelper.GetEntryAssembly()).AddControllersAsServices();

  This is just a workaround and I would like to understand the right approach of handling this case

  • The second issue is with Dependency injection. As I mentioned earlier, the framework services in the Class library are registered in the Startup.cs and they work fine. However each of the Web Application projects could have their own Services and we would like to register them to the same IServiceCollection. This way the Controllers can inject both the framework services as well as the ones registered in the web application project itself. The problem is, how can I get hold of the IServiceCollection object in my Web Application project. I could not come across the right approach for implementing this so far and had to put another workaround to get this working temporarily.

Please let me know the right approach of implementing this.

Thanks,

Ranjith


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>