I've created a custom Scope Accessor (it simply returns the DefaultLifetimeScope) to be able to add a custom scoped lifestyle. The component is then registered as
Component
.For<..>
.LifestyleScoped<CustomScope>()
However, I am at a loss as how to actually start a new CustomScope scope/lifetime. The documentation shows starting a new scope using
using (Container.BeginScope()) {
// ..
}
but my goal is to create/begin/start a specific scope, not that for a generic LifestyleScoped()
registration. The new scope should only affect components explicitly registered to CustomScope; not generic scoped components or components registered against other scoped lifestyles.
What is the process to begin a (My Custom Scope) scope / lifetime?
Please link to the relevant documentation; as I'm asking because I was not able to find it readily. The code is using Castle Windsor 3.3.
Background:
I am coming from Autofac and am looking for the equivalent of an Instance Per Matching Lifetime Scope to establish a UoW over an EF context. There may be multiple UoWs "per request" and there might be different UoWs for different repositories - I would also like the support for nesting in the future.
While there are numerous articles talking about creating a UoW pattern, they are [all] tied (incorrectly, IMOHO) to some context such as HTTP or WFC request - and that is not what this question is about. I am specifically interested in how to start a custom scope that flows down through the call graph and "lives inside" the using block.
Notes:
The BoundTo()
(and LifestyleBoundTo()
/LifestyleBoundToNearest()
) lifestyles work against the object-graph (and requires altering the types) and switching to such is not strictly a solution/answer to this question. However, if a good case can be made for them ..