Quantcast
Viewing all articles
Browse latest Browse all 9386

Inject either parent or child object based on route value in ASP.NET core

How to inject either parent or child object based on route value to a asp.net mvc core controller. If possible by .NET CORE default DI mechanism or something like structure map .

if route value is x i want to inject parent but if route value is y i want to inject child object

public class MyController : Controller {

privateIMyService myService;publicMyController(IMyService svc){
    myService= svc;}

}

public class MyParent : IMyService

public class MyChild: IMyService

//decision of which object ( MyParent object or MyChild object) is injected, is dependent on my route value(25) in

url:     www.Mysite.com/rValue/25


Viewing all articles
Browse latest Browse all 9386

Trending Articles