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

MVC Dependency Injection into classes

$
0
0

Hi,

I have a service (service1) that is added to dependency injection as a singleton class at the start up (startup.cs). I am also implementing IViewLocationExpander (BrandLocationExpandor) in order to do some View location management. I need service1 that is injected at the startup to be available in the BrandLocationExpandor. How can I inject this as I cannot inject it like in a controller and I have the following in the startup.cs

  services.AddSingleton<IService1, service1>();

 services.Configure<RazorViewEngineOptions>(options =>
            {
                options.ViewLocationExpanders.Add(new BrandLocationExpander());
            });

Is there any way I can inject service1 into the above new BrandLocationExpander()

Many thanks

Angelo


Viewing all articles
Browse latest Browse all 9386

Trending Articles



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