C
Join ServerC#
help
AppBuilder class
DDropps10/2/2022
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
how could that be done?
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>();
how could that be done?
BBecquerel10/2/2022
would the
Use
extension method pattern work?BBecquerel10/2/2022
in project B:
Ttebeco10/2/2022
side point: i would stick to the existing ILogger<T> and don't reinvent logging stack
BBecquerel10/2/2022
public static class Extensions
{
public static void AddWpfApp(this IServiceCollection collection)
{
collection.AddSingleton<...>();
}
}
BBecquerel10/2/2022
in project A:
BBecquerel10/2/2022
builder.AddWpfApp();
Ttebeco10/2/2022
you don't need / not supposed to register anything when it comes to logging
DDropps10/2/2022
its not only about logging its just as an example
BBecquerel10/2/2022
project B gets to control what gets registered
BBecquerel10/2/2022
even though project A actually does the registration
Ttebeco10/2/2022
sure 👍 i can only reply with what you shared 😉
DDropps10/2/2022
this would be in project B then right?
DDropps10/2/2022
never heard of that
BBecquerel10/2/2022
it's what you see a lot of libraries do
BBecquerel10/2/2022
like automapper has an extension method
AddAutomapper()
which handles all the registration for youBBecquerel10/2/2022
uhh, the other way around actually i think, now that i re-read your post
BBecquerel10/2/2022
project B is the app you're actually running, right
BBecquerel10/2/2022
and project A is some kind of library or whatever?
BBecquerel10/2/2022
in that case you would have an extension method with
AddSingleton<LoggerForProjectA>()
in project A somewhereBBecquerel10/2/2022
and call the extension method in project B
DDropps10/2/2022
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
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
DDropps10/2/2022
same with other ui components
DDropps10/2/2022
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
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
BBecquerel10/2/2022
sounds like it'll still work then yeah
DDropps10/2/2022
iam refactoring the entire solution architecture for the 3rd time now as the team still isnt happy with it xd
CCisien10/2/2022
Have the bootstrapper be separate from the core so it can reference projects directly
CCisien10/2/2022
Or include it in the outermost layer
CCisien10/2/2022
@Dropps
DDropps10/2/2022
its not having a bootstrapper its not a web app
CCisien10/2/2022
Doesnt matter, if you are encountering circular references, you need to change something
CCisien10/2/2022
I use bootstrapper as a generic term to describe the code that initializes and starts your app
CCisien10/2/2022
It should be in your presentation layer
CCisien10/2/2022
Or separate from the three distinct layers