Getting builder `WebApplicationBuilder` in `ICompo...
# help-with-umbraco
k
Is there a way to get an instance of the
builder
of type
WebApplicationBuilder
in the
Compose
method, we only get
IUmbracoBuilder
the
BuilderHostingEnvironment
member is [obselete] and also it is not used in DI, What I am trying to achieve is that I have a common services layer that already have a lot of configurations that needs the builder to register some of its services, and I do not want to refactor this common layer, also I use
Aspire
client for some of the hosting components which only uses
IHostingBuilder
extension
j
You don't have to use umbracos composers to register DI things, we use it on our website project for Umbraco things fx, but then create our own IServiceCollection extensions that we add in the startup/program file. Where to add it depends a bit on the version you are on, but just be aware that the composers are not required to register things
k
I developing a package that when gets installed to an Umbraco instance it registers everything to this site, till now for developers they just reference my package and that's it, no need to add anything to the program file, and I want to try to keep it this way for separation of concerns and having a better way for future updates
j
Ahh I see, then yea a composer is probably the right thing. What is it you need from the WebApplicationBuilder that you can't access in the composer?
k
Mainly we are using
Aspire
for the end-to-end system to manage and orchestrate different distributed system components like Services, Caching, DBs, Jobs ... etc , most of
Aspire
client packages exposes extensions for
IHostApplicationBuilder
like https://learn.microsoft.com/en-us/dotnet/aspire/caching/stackexchange-redis-integration?tabs=dotnet-cli&pivots=redis#client-integration , also We already have some set of common services and HttpClients that are encapsualted in helper packages that we use and those are also configured through
IHostApplicationBuilder
l
I've tried hard recently, but there is just no way that I know of to get the WebApplicationBuilder or IApplicationBuilder in a Umbraco composer. It makes kind of sense, since the UmbracoBuilder is not an implementation of the WebApplicationBuilder or build on top of it. I would suggest you check out their extension and see what services it registers. You can ofcourse access the ServiceCollection in the UmbracoBuilder, so if you can get to the IServiceCollection level, you are good to go. If you need to register middleware, you can use Umbraco pipeline filters.
20 Views