Hi there umbracos
I am trying to figure out how to register a simple singleton service in the program.cs, but I am a bit lost, since there is a builder, but no services.
How is it supposed to be done?
What is the .AddNotificationHandler doing in this context? I have done this, but it gives an error:
using Umbraco.Cms.Core.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.CreateUmbracoBuilder()
.AddBackOffice()
.AddWebsite()
.AddDeliveryApi()
.AddComposers()
.Services.AddSingleton<IDataService, DataService>()
.Build();
WebApplication app = builder.Build();
The docs says: "
Registering dependencies for your site
When working with your site, and not a package, the recommended way to register dependencies is with the Program.cs file:
builder.CreateUmbracoBuilder()
.AddBackOffice()
.AddWebsite()
.AddDeliveryApi()
.AddComposers()
// If you need to add something Umbraco specific, do it in the "AddUmbraco" builder chain, using the IUmbracoBuilder extension methods.
.AddNotificationHandler<ContentTypeSavedNotification, ContentTypeSavedHandler>()
.Build();"
Register custom service in program.cs Umbraco 13
Hi there umbracos I am trying to figure out how to register a simple singleton service in the program.cs, but I am a bit lost, since there is a builder, but no services.
How is it supposed to be done? What is the .AddNotificationHandler doing in this context? I have done this, but it gives an error:
The docs says: "
Registering dependencies for your site
When working with your site, and not a package, the recommended way to register dependencies is with the Program.cs file:
Seems I got it to work with:
Still not quite sure that I havent missed something..
is working on a reply...