Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments for "The Closure Composition Model" #2

Open
dotnetjunkie opened this issue Jul 9, 2019 · 4 comments
Open

Comments for "The Closure Composition Model" #2

dotnetjunkie opened this issue Jul 9, 2019 · 4 comments

Comments

@dotnetjunkie
Copy link
Owner

@dotnetjunkie dotnetjunkie commented Jul 9, 2019

In the section below, you can leave your comments for this blog post: https://blogs.cuttingedge.it/steven/posts/2019/closure-composition-model/.

Please be aware that a comment posted here will be shown in the comment section of the blog post, using JavaScript. This means that you should consider this a comment directly on my weblog—not as a post on GitHub.

This means that I might

  • Alter your comment—For instance, to correct spelling or make style and layout corrections
  • Delete your comment—In case I delete your comment, I will typically try to contact you to get your question answered. I can, for instance, delete your comment when I feel that the comment
    • Is not constructive
    • Is not related to the topic
    • Is too long
    • Is not helpful to most of my readers
@didiercauvin
Copy link

@didiercauvin didiercauvin commented Feb 20, 2020

Hi Steven and thanks for this article. I have a problem understanding this :

using (ILifetimeScope scope = container.BeginLifetimeScope())
{
    var userContext = scope.Resolve<ClosureUserContext>();
    userContext.UserName = queueContext.UserName;

    // Let Autofac compose the object graph which consists of ClosureUserContext
    var handler = scope.Resolve<IHandler<OrderCancelled>>();

    // Invoking the constructed and initialized graph
    handler.Handle(queueContext.Message);
}

I don't understand where you implement it. I guess it is part of the composition root, but as you call the Handle method, is it part of some kind of proxy?

Regards,
Didier

Loading

@dotnetjunkie
Copy link
Owner Author

@dotnetjunkie dotnetjunkie commented Feb 22, 2020

Hi Didier, The Handle method is part of the IHandler<T> interface. I didn't show that interface, because it is not central to the discussion, and you can replace it with any other interface. But to paint the picture, this is how the IHandler<T> interface might look like:

public interface IHadler<T>
{
    void Handle(T message);
}

For more information on this kind of design, read this old article of mine.

Loading

@didiercauvin
Copy link

@didiercauvin didiercauvin commented Feb 22, 2020

Thanks Steven for taking the time to answer. In fact, I was talking about the whole using (ILifetimeScope scope = container.BeginLifetimeScope()) block instead of the handler method. I thought it had to be implemented in a proxy but because of the scope.Resolve calls, I don't understand in which class the ILifetimeScope block should be implemented. In the composition root certainly but where exactly?

Loading

@dotnetjunkie
Copy link
Owner Author

@dotnetjunkie dotnetjunkie commented Feb 23, 2020

I don't understand in which class the ILifetimeScope block should be implemented. In the composition root certainly but where exactly?

The example in question shows a message that is pulled in from some sort of message queue. So in this case, it is a part of the composition root that is strongly coupled to the messaging infrastructure. It could be, for instance, hooked to some sort of callback mechanism provided by the messaging infrastructure.

Also note that this code example is not realistic, per se, because it requests a handler for a specific message OrderCancelled, while in reality you likely want to make this code more generic, reusable. However, to make the code less abstract, and more understandable to the context of this post, I decided to use concrete types.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants