-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add webhooks extension methods #15432
Add webhooks extension methods #15432
Conversation
Hi there @erikjanwestendorp, thank you for this contribution! 👍 While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:
Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution. If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request. Thanks, from your friendly Umbraco GitHub bot 🤖 🙂 |
Maybe I haven't merged everything into |
@nul800sebastiaan Thanks for your reply! I know that a fluent API has been added, and the methods added in this PR also use it. However, the methods added in this PR make it possible to do this directly from the |
I see, I didn't read much further since you mentioned an "old" method.. (
|
@nul800sebastiaan I can well imagine that you give that advice, although I think it can be convenient for small applications to quickly modify the public class MyComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.AddAllCmsWebhookEvents();
}
} or: public class MyComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.ConfigureCmsWebhookEvents(cmsBuilder => cmsBuilder.AddContentType());
}
} |
In my opinion we already have too many extension methods on The main reason for adding these is to keep the fluent/chained calls, so you don't have to use composers or resort to the following: WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
var umbracoBuilder = builder.CreateUmbracoBuilder()
.AddBackOffice()
.AddWebsite()
.AddDeliveryApi()
.AddComposers();
umbracoBuilder.WebhookEvents().AddCms(cmsBuilder => cmsBuilder.AddLanguage());
umbracoBuilder.Build();
WebApplication app = builder.Build(); But in that case, I'd suggest creating a single 'generic' public static class UmbracoBuilderExtensions
{
public static IUmbracoBuilder Compose(this IUmbracoBuilder builder, Action<IUmbracoBuilder> compose)
{
compose(builder);
return builder;
}
} Which would allow you to keep the fluent approach: WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.CreateUmbracoBuilder()
.AddBackOffice()
.AddWebsite()
.AddDeliveryApi()
.AddComposers()
.Compose(builder => builder.WebhookEvents().AddCms(cmsBuilder => cmsBuilder.AddLanguage()))
.Compose(builder =>
{
// You can even use multiple lines, e.g. to add more webhook events
builder.WebhookEvents().AddCms(cmsBuilder => cmsBuilder.AddUser());
// This would also make the following extension method obsolete:
builder.AddWebhookEvent<ImportedPackageWebhookEvent>();
})
.Build();
WebApplication app = builder.Build(); Although I'm not 100% sure whether this makes sense though (and if it should be named |
@nul800sebastiaan @ronaldbarendse From what I read, the individual extension methods are certainly not desirable 🤣 . So, this PR can be closed for now I guess? However, it might be a good idea to decide whether to remove all extension methods or to remove them and create a generic |
@nul800sebastiaan / @erikjanwestendorp |
@bielu Never mind, I retract that, personal preference. |
My main concern regarding this PR is that it's adding an additional way of configuring webhooks, just so you can chain Adding a single I do acknowledge this is slightly more verbose, but having a single way of doing things that also supports the full API (like inserting, removing, etc.) should be enough to justify that... |
@ronaldbarendse Thanks again for you reply! I think this PR can be closed? I will create a new PR for the single Compose() method. I assume the methods can only be made obsolete in the v14 branch? |
Thanks all! @erikjanwestendorp @ronaldbarendse we happy to close this one now we have the another PR? Do you have a link to that at all? |
Prerequisites
Description
Add two
IUmbracoBuilder
extension methods to theUmbracoBuilder.CollectionBuilders.cs
class.AddAllCmsWebhookEvents
This method allows for easy registration of all CMS WebhookEvents from the
Startup.cs
/Program.cs
class. See the code example below:ConfigureCmsWebhookEvents
This method can be used to configure
WebhookEvents
in theStartup.cs
/Program.cs
class, for example:When #15424 is merged the default events can be deleted like so: