Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes. I don't see why you couldn't. However... </p> <p>although the use of interception often loosens the need to have a clean and <a href="https://en.wikipedia.org/wiki/SOLID" rel="nofollow">SOLID</a> design, when you want to do this, you still need a SOLID design.</p> <p>I've written about these kind of designs that enable this <a href="https://cuttingedge.it/blogs/steven/pivot/entry.php?id=91" rel="nofollow">here</a>, and what it comes down to is that you will have model the operations you want to wrap behind a design, such as an <code>ICommandHandler&lt;T&gt;</code> with a <code>Handle(T)</code> method. With such a design, you can create a decorator (or in Unity's case an interceptor) that wraps a real class with a class that adds a child container like this:</p> <pre><code>public class ChildContainerCommandHandlerDecorator&lt;T&gt; : ICommandHandler&lt;T&gt; { private readonly ICommandHandler&lt;T&gt; decorated; private readonly Container container; public ChildContainerCommandHandlerDecorator( ICommandHandler&lt;T&gt; decorated, Container container) { this.decorated = decorated; this.container = container; } public void Handle(T command) { using (container.CreateChildContainer()) { this.decorated.Handle(command); } } } </code></pre> <p>And a decorator that adds a transaction scope like this:</p> <pre><code>public class TransactionCommandHandlerDecorator&lt;T&gt; : ICommandHandler&lt;T&gt; { private readonly ICommandHandler&lt;T&gt; decorated; public TransactionCommandHandlerDecorator( ICommandHandler&lt;T&gt; decorated) { this.decorated = decorated; } public void Handle(T command) { using (var scope = new TransactionScope()) { this.decorated.Handle(command); scope.Complete(); } } } </code></pre> <p>By wrapping real handlers in both decorators, you can extend handlers with this behavior. Of course, decorators is a concept that Unity is unable to handle, but you can easily rewrite this using interceptors when working with Unity, but again, good design is your only friend here.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload