C
C#3y ago
Dropps

AppBuilder class

hello there iam currently trying to think of a solution so i can make myself a AppBuilder without needing to reference all projects directly basicly i have a Program.cs from a wpf app in Project B but in project A i want to be able to say something like
cs
builder.AddSingleton<LoggerForProjectA>();
cs
builder.AddSingleton<LoggerForProjectA>();
how could that be done?
15 Replies
Becquerel
Becquerel3y ago
would the Use extension method pattern work? in project B:
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Becquerel
Becquerel3y ago
public static class Extensions
{
public static void AddWpfApp(this IServiceCollection collection)
{
collection.AddSingleton<...>();
}
}
public static class Extensions
{
public static void AddWpfApp(this IServiceCollection collection)
{
collection.AddSingleton<...>();
}
}
in project A: builder.AddWpfApp();
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Dropps
DroppsOP3y ago
its not only about logging its just as an example
Becquerel
Becquerel3y ago
project B gets to control what gets registered even though project A actually does the registration
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Dropps
DroppsOP3y ago
this would be in project B then right? never heard of that
Becquerel
Becquerel3y ago
it's what you see a lot of libraries do like automapper has an extension method AddAutomapper() which handles all the registration for you uhh, the other way around actually i think, now that i re-read your post project B is the app you're actually running, right and project A is some kind of library or whatever? in that case you would have an extension method with AddSingleton<LoggerForProjectA>() in project A somewhere and call the extension method in project B
Dropps
DroppsOP3y ago
the entire project is a 3 Layer wpf application having 3 main parts UI Core and HostProcess HostProcess is the first thing that starts wich boots up the entire application and launches the Launcher wpf project the wpf project might need some parts of core then wich is a class library same with other ui components one other side part we also have which is the plugin managment like for logging we make a own project wich implements our plugin structure and load it in with the host process before the wpf apps start
Becquerel
Becquerel3y ago
sounds like it'll still work then yeah
Dropps
DroppsOP3y ago
iam refactoring the entire solution architecture for the 3rd time now as the team still isnt happy with it xd
Cisien
Cisien3y ago
Have the bootstrapper be separate from the core so it can reference projects directly Or include it in the outermost layer @Dropps
Dropps
DroppsOP3y ago
its not having a bootstrapper its not a web app
Cisien
Cisien3y ago
Doesnt matter, if you are encountering circular references, you need to change something I use bootstrapper as a generic term to describe the code that initializes and starts your app It should be in your presentation layer Or separate from the three distinct layers
Want results from more Discord servers?
Add your server