C
C#2y ago
Carsillas

Dependency injection questions

I've been learning dependency injection in a non-web-api environment (tagging as asp.net anyways since it's pretty related I feel) and have a few questions: 1. Is there a proper way to bind an interface to a hosted service, is this something I should just in general avoid? If so why? The situation in question is I want to bind a "network service" that will handle transporting messages over the network, but I don't necessarily always want it to have the same transport, was hoping to abstract this to an interface. It still would be nice to have it hosted so it can do some setup. 2. Is it standard practice for hosted services to be in charge of creating scopes? If so, is it normal that examples I've seen online use things like GetRequiredService which seems more like service locator pattern? 3. I have found that there is no way to swap out implementations for different scopes, is there a usual way of achieving something similar? For one scope I want to have IFoo bound to Foo and in another scope I want to have IFoo bound to Bar (these would specifically be Scoped services, not transient/singleton/hosted)
0 Replies
No replies yetBe the first to reply to this messageJoin