Skip to content

Improve fluent API with builder pattern when registering Azure Service Bus message pump  #152

Closed

Description

@tomkerkhove

Is your feature request related to a problem? Please describe.
Improve fluent API with builder pattern so that we control what the following methods are that can be called.

services.AddServiceBusQueueMessagePump(secretName, options => options.JobId = jobId)
            .WithServiceBusMessageHandler<OrdersAzureServiceBusMessageHandler, Order>();
services.WithAutoRestartServiceBusQueueMessagePumpOnRotatedCredentials(...);

This is to make it more clear and less verbose since every extension we have today is returning IServiceCollection.

This also helps new people to explore what the other options are for configuring the runtime.

Describe the solution you'd like
Return a IServiceBusMessagePumpBuilder which enforces you to call WithServiceBusMessageHandler, WithAutoRestartOnRotatedCredentials and/or ... after AddServiceBusQueueMessagePump

services.AddServiceBusQueueMessagePump(secretName, options => options.JobId = jobId)
+++     .WithAutoRestartOnRotatedCredentials(...)
        .WithServiceBusMessageHandler<OrdersAzureServiceBusMessageHandler, Order>();
--- services.WithServiceBusMessageHandler<OrdersAzureServiceBusMessageHandler, Order>(); <-- No longer possible on services directly
--- services.WithAutoRestartServiceBusQueueMessagePumpOnRotatedCredentials(...); <-- No longer possible on services directly

What I would not do, however, is have a Build method at the end.

Describe alternatives you've considered
Nothing specifically, but open to suggestions.

Additional context
Add any other context or screenshots about the feature request here.

Activity

  1. added this to the v1.0.0 milestone on Feb 8, 2021
  2. tomkerkhove commented on Feb 8, 2021

    @tomkerkhove
    ContributorAuthor

    Thoughts @fgheysels ?

  3. stijnmoreels commented on Feb 9, 2021

    @stijnmoreels
    Member

    Yes, was something I thought about too, but didn't go through with it because it's actually some kind of breaking change, but since we're almost on the next major version we can indeed thing about this.
    It's an approach that's also more in line with how the other .NET services are registered.

  4. fgheysels commented on Feb 10, 2021

    @fgheysels
    Member

    What I would not do, however, is have a Build method at the end.

    What exactly do you mean ? You'll need to have something that actually finishes the setup of your builder, and leads to building the messagepump ? Or do you mean that this should be hidden ?

  5. stijnmoreels commented on Feb 11, 2021

    @stijnmoreels
    Member

    What I would not do, however, is have a Build method at the end.

    What exactly do you mean ? You'll need to have something that actually finishes the setup of your builder, and leads to building the messagepump ? Or do you mean that this should be hidden ?

    The actual build up will be when internally the .BuildServiceProvider will be called. This fluent API is about registration, not creation.

  6. tomkerkhove commented on Feb 11, 2021

    @tomkerkhove
    ContributorAuthor

    @fgheysels Ideally I would just have to do this:

    services.AddServiceBusQueueMessagePump(secretName, options => options.JobId = jobId)
            .WithAutoRestartOnRotatedCredentials(...)
            .WithServiceBusMessageHandler<OrdersAzureServiceBusMessageHandler, Order>();
    

    Which doesn't require a Build at the end, but if it's required then that's fine - Although a better name should be used then.

    However, it could lead to cases where people didn't call it, nothing is happening and they are confused. Docs could help with that, but that wouldn't be enough.

  7. changed the title [-]Improve fluent API with builder pattern[/-] [+]Improve fluent API with builder pattern when registering Azure Service Bus message pump [/+] on Feb 11, 2021
  8. stijnmoreels commented on Feb 19, 2021

    @stijnmoreels
    Member

    If we do this (separate services), singletons defined could be created more than once, though. Just a remark.

  9. tomkerkhove commented on Feb 22, 2021

    @tomkerkhove
    ContributorAuthor

    Isn't that something we can/should manage?

  10. stijnmoreels commented on Mar 2, 2021

    @stijnmoreels
    Member

    Isn't that something we can/should manage?

    'Can' in 'We can circumvent that?'
    'Should' as in 'We should circumvent that?'

  11. tomkerkhove commented on Mar 9, 2021

    @tomkerkhove
    ContributorAuthor

    I think we should be able to manage that, no?

  12. stijnmoreels commented on Mar 10, 2021

    @stijnmoreels
    Member

    I think we should be able to manage that, no?

    The problem I'm referring is that with separate service collections, they don't know from each other if a singleton has already been created. But that's only the case if the service descriptors don't hold the state (as in "is instance already created?") but the service provider does. So, it could be that the problem I think there is, doesn't exists. 😄 If that makes sense.

    Something we can write a test for, of course, when we take up this issue.

  13. stijnmoreels commented on Apr 1, 2021

    @stijnmoreels
    Member

    I think we should be able to manage that, no?

    The problem I'm referring is that with separate service collections, they don't know from each other if a singleton has already been created. But that's only the case if the service descriptors don't hold the state (as in "is instance already created?") but the service provider does. So, it could be that the problem I think there is, doesn't exists. 😄 If that makes sense.

    Something we can write a test for, of course, when we take up this issue.

    Just tested this, it seems like the state is indeed being held by the IServiceProvider and not the ServiceDescriptor which means that singletons could be created more than once (1 / service collection).

    Or.... we don't work with seperate service collections at all and just make it more fluently.

  14. tomkerkhove commented on Apr 1, 2021

    @tomkerkhove
    ContributorAuthor

    I'll leave it up to your judgement to be honest. But what do you mean with more fluently? Can you add a sample?

  15. stijnmoreels commented on Apr 2, 2021

    @stijnmoreels
    Member

    I'll leave it up to your judgement to be honest. But what do you mean with more fluently? Can you add a sample?

    Ok, I'll wait till #170 is finished, I'll safe us some merge conflicts. Oh, and with 'more fluently' I only mean this issue. That we don't look for separate service collections (for each message pump) but that we only update the message handling extensions with better discovery (like proposed here).

    If we don't use separate service collections, we can do this, though:

    services.AddServiceBusQueueMessagePump(secretName)
            .WithServiceBusMessageHandler<OrdersAzureServiceBusMessageHandler, Order>(); // <-- available for  message pump below
    
    services.AddServiceBusTopicMessagePump(secretName);

    But maybe that's ok. It's possible today. Maybe we should just look first for making this more better discoverable (as the initial request was in this issue).

  16. tomkerkhove commented on Apr 8, 2021

    @tomkerkhove
    ContributorAuthor

    That was indeed what I was looking for, users should just call the AddServiceBusQueueMessagePump every time they want to add a new pump. So we are good to go then?

  17. stijnmoreels commented on Apr 8, 2021

    @stijnmoreels
    Member

    That was indeed what I was looking for, users should just call the AddServiceBusQueueMessagePump every time they want to add a new pump. So we are good to go then?

    Yes, all good. I'll first finish with this one #141 as it will also help with Azure Functions later on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalAll current proposals

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions