Premise: This is for learning purpose.
I'm trying to adapt my Console Application code to be served through a WPF Application GUI that I would like to create.
One problem is struggling me.
Actually I'm using something like a procedural approach, even if it's async in some path, how I could decouple my code to be the server for a WPF application View?
Actually I have models representing the managers, some helpers with function to edit queries that I got from controller, and DB Entities, scaffold-ed from an existing DB.
Example:
static async Task Main(string[] args)
{
//IConcessionario sisal = new Sisal();
IManager pManager = new PrimaryManager(new HttpClient());
UserController controller = new UserController(new DBContext());
List<UserQuery> userQueries;
Console.WriteLine("Starting");
userQueries = await pManager.GetAllUsersQueriesAsync(users);
Console.WriteLine("InsertInDb");
/* code to insert data in db */
}
public class UserController {
private DBContext context;
public UserController(DBContext context)
{
this.context = context;
}
public function List<User> GetAll(){
await using (var ctx = new DBContext())
{
return context.Users
.Where(s => s.Active == true)
.Select(s => new User() { /** code to populate **/ }));
}
}
}
public class PrimaryManager : IManager {
private readonly HttpClient client;
public PrimaryManager(HttpClient client)
{
this.client = client;
}
public function List<UserQueries> GetAllUsersQueriesAsync()
{
var queries = new List<UserQuery> queries;
foreach(var user in users)
{
var query = new UserQuery(){ /* code to populate */ };
queries.Add(query);
Console.WriteLine($"Added {user.Name} query {query.id}");
}
}
}
Look at Console.WriteLine I put everywhere, how I could move it away from code and modify it to be catched at the same way from the console app and the WPF view?
I'm writing here because I miss the fundamental like: Should my WPF application be aware of the other solution? Should I reference it?