Steven
Steven

Reputation: 890

Castle Windsor Component Lifestyle advice

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

Answers (2)

Nexus
Nexus

Reputation: 294

  • Session PerWebRequest
  • Repositories depending on using a ISessionProvider (could be singleton), if they are injected with the session they are bound to the lifetime of the session so PerWebRequest
  • Validators : expensive to create ???? ok if they need a repo or a session same applies here as the repos itself
  • services: can probably be also per web request

Upvotes: 0

Crixo
Crixo

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

Related Questions