How to "BeginScope" for a specific Custom Scoped style in Windsor Castle?

I created a custom Scope helper object (it just returns DefaultLifetimeScope) to add a custom lifestyle. Then the component is registered as

Component
   .For<..>
   .LifestyleScoped<CustomScope>()

However, I do not understand how to start a new area / time using CustomScope. The documentation shows the start of a new area with

using (Container.BeginScope()) {
   // ..
}

but my goal is to create / start / start a specific area, and not for general registration LifestyleScoped(). The new scope should only affect components explicitly registered in CustomScope; not common components or components registered in relation to other types of life in the coverage area.

/ ?

, ; , . Castle Windsor 3.3.


:

Autofac , UoW EF. UoW " ", UoW - .

UoW, [] (, IMOHO) - , HTTP WFC, , . , , " " .


:

BoundTo() ( LifestyleBoundTo()/LifestyleBoundToNearest()) ( ), / . , .

+4
1

Container.BeginScope() CallContextLifeTimeScope.

https://github.com/castleproject/Windsor/blob/aa9b8b353ee2e533d586495eec254e216f800c09/src/Castle.Windsor/MicroKernel/Lifestyle/LifestyleExtensions.cs

using Scope = Castle.MicroKernel.Lifestyle.Scoped.CallContextLifetimeScope;

public static class LifestyleExtensions
{
    public static IDisposable BeginScope(this IKernel kernel)
    {
        return new Scope(kernel);
    }
    /* rest of the code removed for simplicity */
}

ILifetimeScope.

Container.BeginScope() new CustomScope() , , " " .

Container.BeginScope() CustomScope , , .

+1

Source: https://habr.com/ru/post/1569445/


All Articles