I am writing an app using WPF. I want to new up an instance of my service class every time I make a call to my database.
How do I do that using Simple Injector? Should lower layers in my app have knowlege of the container?
In my viewmodel I have an instance of DBClient. DBClient is responsible for creating/disposing an instance of the Service class. The service class is passed the dbcontext and from there it queries the database (I could also new up the dbcontext in the service, either way my question is the same).
Here is the object hierarchy:
ViewModel(DBClient) // DBClient.GetCustomers()
DBClient(Services???) // using(Services) { Services.GetCustomers() } // Problem here...I need to create/dispose Services
Services(db) // return db.Customers
DbContext(connectionString)
connectionString
My question might be related to this one: DbContext Lifestyle per Screen/ViewModel (WPF + Simple Injector) but in my case I want to create/dispose the context on a per use basis, as might be done with a wcf/rest service wrapper.