In a web app, its reasonable to use IoC/DI to get database sessions, DAOs and whatever, because it’s not you that is calling the “event”, is the injector. You just need to declare the proper parameter in your event function.
But in a winforms app, its you and only you that calls the functions. There is no “query string handler” for you.
Really sounds impossible to change from
private void button1_Click(object sender, EventArgs e);
to
private void button1_Click(object sender, EventArgs e, DbSession dbSession);
and the “handler” automatically inject stuff for you.
So, the thing is: In winforms i just have to implement a singleton or static class that contains all my “util” instances, like SessionFactory and etc?
So for injection in winforms there is no design pattern or best practices?
There are a couple of different flavors of Dependency Injection
Service Locator – Use a well known class that knows how to retrieve and create dependencies. Not technically DI, but this is what most DI/IoC container tools really do.
Dependency Injection solves the issue (little bit of tight coupling) by putting the creation of object outside the scope of the container.
check out detailed explanation with examples