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

Expose the internal behavior in order to decorate it #2485

Open
danielmarbach opened this issue Oct 17, 2014 · 5 comments
Open

Expose the internal behavior in order to decorate it #2485

danielmarbach opened this issue Oct 17, 2014 · 5 comments
Milestone

Comments

@danielmarbach
Copy link
Contributor

Let's consider this example:

https://github.com/Particular/NServiceBus/blob/develop/src/NServiceBus.AcceptanceTests/PipelineExt/FilteringWhatGetsAudited.cs

The problem of the replace is that you need to reimplement the existing auditing behavior by copy pasting the code. It would be awesome if the pipeline allows to decorate existing behaviors without knowing the concrete class of the core behavior. This could for example be achieved with the follwowing syntactic sugar:

class FilteringAuditBehavior : IBehavior<IncomingContext>
            {
                public void Invoke(IncomingContext context, Action next)
                {
                    var auditBehavior = context.Get<IBehavior<IncomingContext>>(WellKnownSteps.AuditBehavior);
                    var auditResult = new AuditFilterResult();
                    context.Set(auditResult);
                    next();

                    //note: and rule operating on the raw TransportMessage can be applied here if needed.
                    // Access to the message is through: context.PhysicalMessage. Eg:  context.PhysicalMessage.Headers.ContainsKey("NServiceBus.ControlMessage")
                    if (auditResult.DoNotAuditMessage)
                    {
                        return;
                    }
                    auditBehavior.Invoke(context, next);
                }

                //here we inject our behavior
                class AuditFilteringOverride : INeedInitialization
                {
                    public void Customize(BusConfiguration configuration)
                    {
configuration.Pipeline.Replace(WellKnownStep.AuditProcessedMessage, typeof(FilteringAuditBehavior), "A new audit forwarder that has filtering");
                    }
                }
            }

The classes can be left internal but it allows the user to decorate existing behaviors. Thoughts?

@andreasohlund
Copy link
Member

I like it!

@SimonCropp
Copy link
Contributor

confused. how is this any different than the currently supported "wrapping a behaviour"?

@SimonCropp
Copy link
Contributor

i now understand and withdraw my objection

@danielmarbach
Copy link
Contributor Author

Cool!

@danielmarbach
Copy link
Contributor Author

This could be solved with the internal service bag pretty easily.

@andreasohlund andreasohlund modified the milestone: Future Oct 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants