I'm new to dependency injection in .net core. So far i was using interface and was easily able to inject dependencies via DI framework.
Now, I have one external library which holds mongo DB connection and provides necessary database operation calls.
The class accepts two parameters i.e connection string and database name. As MOQ can inject dependency without interface so i tried to add below code
services.AddSingleton<MongoManager>();
As MongoManager
Class accepts connection string so this would not work.
After this tried below code.
services.AddSingleton(new MongoManager(userName, database));
Above code works as expected however it creates object at the time of app start. In other cases .net framework gives instance of a class when its first time requested, however here its getting created without being asked by app anywhere. Also would this object be disposed when app terminates? Is there any way to register classes and tell the framework to pass certain arguments like connection string, database Name etc. to the class when the instance requested first time.