Reputation: 890
I'm looking for some advice on how to best configure this situation. I have the following components in an ASP MVC application.
I'm looking at how best to configure Services and Repositories. On the surface it seems like they could both be configured the same. Repositories only dependency (passed in on the constructor) is ISession. Services only dependencies (passed in on the constructor) are Repositories. When a Service needs a Validator it gets it from the ServiceLocator. Validators get Repositories in the constructor. I think that because Validators are Singleton passing Transient Repositories is problematic because the Validator will hold onto a Repository that has a disposed ISession.
Any help here would be greatly appreciated.
Upvotes: 1
Views: 527
Reputation: 294
Upvotes: 0
Reputation: 3070
Any repository that rely on an UnitOfWork(ORM, custom implementaton...) has to be transient or at least same UoW lifestyle .
In case your Validator needs a "read-only" access to the storage via Repository... you may consider to have a Singleton Repository but be very carefull on its implementation
Upvotes: 1