C
C#9mo ago
DINH-iy

❔ Hostbuilder, WPF and adding more class library's

I have my WPF project where i use hostbuilder to handle some dependency's, this works good with another Class library i have using EFcore. I want to add another class library where i handle business logic but im kinda lost in how hostbuilder actually works and what the recommended strategy is
3 Replies
Pobiega
Pobiega9mo ago
Hostbuilder does nothing magical at all its just a convenient bundled ConfigurationBuilder + ServiceCollection + IHostedService runner So for your business logic library, you'd just create a library with an IServiceCollection extension method that registers the logic classes then you just request those classes in your WPF app, via constructors (as you said you're using DI for your WPF app already)
JakenVeina
JakenVeina9mo ago
using the generic host architecture is probably overkill in a WPF app the main things it does for you are application lifetime management, and management of multiple hosted "services" in WPF, you already HAVE application lifetime management, through WPF's Application class and you only really have one "service" to be hosted, which is the WPF app itself if all you're looking for is a DI/IoC library, Host/HostBuilder don't actually DO any of that, they're just using Microsoft.Extensions.DependencyInjection which you can pull in and use directly
Accord
Accord9mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.