Thus, in my CQRS-based web-based error tracking API, I will reorganize my code before developing and implementing unit tests (which must have come first); I have this class and constructor:
public class BugCommandHandler : IBugCommandHandler { private BugContext db; public BugCommandHandler(BugContext bugContext) { db = bugContext; }
In my controller, I have this:
public class BugsController : Controller { private IBugCommandHandler commandHandler; private BugContext db; public BugsController(BugContext bugContext, IBugCommandHandler bugCommandHandler) { db = bugContext; commandHandler = bugCommandHandler; } }
And finally, in my Startup class, I introduced a dependency using
services.AddSingleton<IBugCommandHandler, BugCommandHandler>();
My unit tests and manual integration tests work fine, as they did when I manually called this without DI.
How does the BugCommandHandler implementation now work as if it were called with the database context in its constructor (behind the scenes "magic")? What is his βprocess of achieving this?
I checked (not so) some source code in the Github repository, but cannot find where this could happen.
I might be missing out on something important, or it might just be hidden, as it is still in pre-release.
c # dependency-injection asp.net-core entity-framework cqrs
Joel lord
source share