❔ Automatic discovery of scoped services without a marker interface
In the past, I had an
IService
interface which defined a (singleton at the time) service and a contract for certain service-level init functionality etc.
This was coupled with an extension method which used reflection to find all IService
implementation types and register them with my service provider at startup.
I'm trying to do the same thing with scoped services, but I'm struggling to think of ANYTHING to put on this prospective IScopedService
interface, and I always feel like marker interfaces are...smelly. Any suggestions? Or should I just ignore my gut feeling and be happy with a marker interface for this extremely specific usecase?6 Replies
If you want to find them via reflection, you need either an interface, base class or an attribute to look for
For sure, I'm not trying to avoid using an interface. Maybe an attribute would be better, as that fits the "marker" moniker better than an interface which does nothing
Kinda forgot I could do that
Yup
this also opens the door to source gen usage
Well technically you could use something like naming convention to register service. Like wolverine is doing for command handlers
https://wolverine.netlify.app/tutorials/getting-started.html#snippet-sample_quickstart_issuecreatedhandler
Getting Started | Wolverine
Next Generation Command and Message Bus for .NET
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.