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

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

Closed
tomkerkhove opened this issue Feb 8, 2021 · 15 comments · Fixed by #172
Closed
Labels
proposal All current proposals
Milestone

Comments

@tomkerkhove
Copy link
Contributor

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.

@tomkerkhove tomkerkhove added the proposal All current proposals label Feb 8, 2021
@tomkerkhove tomkerkhove added this to the v1.0.0 milestone Feb 8, 2021
@tomkerkhove
Copy link
Contributor Author

Thoughts @fgheysels ?

@stijnmoreels
Copy link
Member

stijnmoreels commented Feb 9, 2021

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.

@fgheysels
Copy link
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 ?

@stijnmoreels
Copy link
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.

@tomkerkhove
Copy link
Contributor Author

@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.

@stijnmoreels stijnmoreels changed the title Improve fluent API with builder pattern Improve fluent API with builder pattern when registering Azure Service Bus message pump Feb 11, 2021
@stijnmoreels
Copy link
Member

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

@tomkerkhove
Copy link
Contributor Author

Isn't that something we can/should manage?

@stijnmoreels
Copy link
Member

Isn't that something we can/should manage?

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

@tomkerkhove
Copy link
Contributor Author

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

@stijnmoreels
Copy link
Member

stijnmoreels commented Mar 10, 2021

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.

@stijnmoreels
Copy link
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.

@tomkerkhove
Copy link
Contributor Author

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

@stijnmoreels
Copy link
Member

stijnmoreels commented Apr 2, 2021

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).

@tomkerkhove
Copy link
Contributor Author

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?

@stijnmoreels
Copy link
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
Labels
proposal All current proposals
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants