Can anyone think of a good solution for getting IOC into a console application?
At the moment we are just using a static class with the following method:
public static T Resolve<T>()
{
return dependencyResolver.Resolve<T>();
}
I would like the experience to be seamless but cannot think of a way of achieving this from a console application.
Run the appPress Ctrl + F5 to run the program without debugging. A console window opens with the text "Hello World!" printed on the screen. Press any key to close the console window.
ASP.NET Core supports the dependency injection (DI) software design pattern, which is a technique for achieving Inversion of Control (IoC) between classes and their dependencies.
In . NET Core, it runs from the dll, so you have to just run the application by running the command prompt and using the command - dotnet run. Open your command prompt and go to that folder where your application persists.
You will have to make a service locater call (Resolve<T>()
) somewhere. The trick is to get it as out-of-the-way as possible. For console applications this bootstrapping happens in the Main()
method. Do it there and minimize those Resolve calls elsewhere and you'll be great. For most dependencies, use constructor injection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With