as long as DtoService.GetDtos()
it is being used,using var context = new dtoContext(...)
itcontext
gets properly disposed of even though you're creating DtoService
without DI. It's short-lived and doesn't hold resources, so there's no memory leak risk and no need to manually dispose of anything. MyService
since you're not holding the EF context there, your provider pattern with DataService
is a good way to avoid cluttering DI with multiple DB context services make sure you don’t accidentally hold onto instances of DtoService
or the context longer than needed