Click here to Skip to main content
14,739,836 members
Home » Discussions » C#
   

C#

 
GeneralRe: .Net Core Windows App, using database repositories Pin
jkirkerx4-Sep-20 14:45
professionaljkirkerx4-Sep-20 14:45 
GeneralRe: .Net Core Windows App, using database repositories Pin
Mycroft Holmes4-Sep-20 16:14
professionalMycroft Holmes4-Sep-20 16:14 
GeneralRe: .Net Core Windows App, using database repositories Pin
Gerry Schmitz5-Sep-20 5:40
mveGerry Schmitz5-Sep-20 5:40 
GeneralRe: .Net Core Windows App, using database repositories Pin
jkirkerx5-Sep-20 8:32
professionaljkirkerx5-Sep-20 8:32 
GeneralRe: .Net Core Windows App, using database repositories Pin
Gerry Schmitz5-Sep-20 9:46
mveGerry Schmitz5-Sep-20 9:46 
AnswerRe: .Net Core Windows App, using database repositories Pin
Richard Deeming6-Sep-20 23:30
mveRichard Deeming6-Sep-20 23:30 
GeneralRe: .Net Core Windows App, using database repositories Pin
jkirkerx7-Sep-20 7:58
professionaljkirkerx7-Sep-20 7:58 
GeneralRe: .Net Core Windows App, using database repositories Pin
jkirkerx7-Sep-20 10:14
professionaljkirkerx7-Sep-20 10:14 
It works, pretty fast speed.
But it's kind of weird.

Dependency Injection in Win Forms or Desktop Application .NET Core | TheCodeBuzz

I set up the forms, and used my main Form.
And then from the main form, passed it to the menu form, and next to the Amazon form, deep down to dialog forms.
I kind of thought the forms would just pick up respository or service.
private static void ConfigureServices(IServiceCollection services)
{
    services.AddScoped<MainForm>();
    services.AddScoped<MenuForm>();
    services.AddScoped<AmazonForm>();
    services.AddScoped<AmazonDownloadForm>();
    services.AddScoped<AmazonOrderDialogForm>();
    services.AddScoped<AmazonViewOrdersForm>();
    services.AddScoped<DownloadFileProcessorDialog>();
    services.AddScoped<EBayForm>();
    services.AddScoped<EBayDownloadForm>();            

<pre>
services.AddTransient<IOrdersRepository, OrdersRepository>();
services.AddSingleton<IGmailSender, GmailSender>();

}

Called the main form
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
{
    var mainForm = serviceProvider.GetRequiredService<MainForm>();
    mainForm.Shown += Main_Shown;
    mainForm.FormClosed += Main_FormClosed;

    // Run the Main Form
    Application.Run(mainForm);
} 
Main form loads the menu form
var menuForm = new MenuForm(_ordersRepository)
{
   MdiParent = this,
   Dock = DockStyle.Fill
};
menuForm.Show();
Menu Form loads the Amazon Form
private void Btn_Amazon_Click(object sender, EventArgs e)
{
    // close all the open forms
    for (var i = Application.OpenForms.Count - 1; i >= 1; i += -1)
    {
        var form = Application.OpenForms[i];
        if (form.Name != "MainForm")
            form.Close();
    }

    var amazonForm = new AmazonForm(_ordersRepository)
    {
        MdiParent = MainForm.ActiveForm,
        Dock = DockStyle.Fill
    };
    amazonForm.Show();
    Application.DoEvents();
}

Well at least I got first working.
I'll play around with the 2nd part, and do lots or reading on the subject.
But the orderRepository works, my test example. I have 10 db respositories and don't want to pass them all up the chain.
I thought is was hard to understand how it works for web projects, this is probably more simple, but I just don't get it yet.
If it ain't broke don't fix it
Discover my world at jkirkerx.com

GeneralRe: .Net Core Windows App, using database repositories Pin
jkirkerx7-Sep-20 11:29
professionaljkirkerx7-Sep-20 11:29 
GeneralRe: .Net Core Windows App, using database repositories Pin
jkirkerx7-Sep-20 13:12
professionaljkirkerx7-Sep-20 13:12 
Question.NetCore dependency injection and optional params on assembly scanning Pin
Member 148747204-Sep-20 9:17
MemberMember 148747204-Sep-20 9:17 
AnswerRe: .NetCore dependency injection and optional params on assembly scanning Pin
Richard Deeming6-Sep-20 23:23
mveRichard Deeming6-Sep-20 23:23 
QuestionHow to create a method in a User control Pin
Member 147923934-Sep-20 8:49
MemberMember 147923934-Sep-20 8:49 
AnswerRe: How to create a method in a User control Pin
Mycroft Holmes4-Sep-20 13:08
professionalMycroft Holmes4-Sep-20 13:08 
GeneralRe: How to create a method in a User control Pin
Member 147923935-Sep-20 8:34
MemberMember 147923935-Sep-20 8:34 
AnswerRe: How to create a method in a User control Pin
Ralf Meier4-Sep-20 22:18
professionalRalf Meier4-Sep-20 22:18 
GeneralRe: How to create a method in a User control Pin
Member 147923935-Sep-20 8:33
MemberMember 147923935-Sep-20 8:33 
AnswerRe: How to create a method in a User control Pin
Ralf Meier5-Sep-20 13:11
professionalRalf Meier5-Sep-20 13:11 
GeneralRe: How to create a method in a User control Pin
Member 147923935-Sep-20 13:41
MemberMember 147923935-Sep-20 13:41 
AnswerRe: How to create a method in a User control Pin
Ralf Meier6-Sep-20 3:29
professionalRalf Meier6-Sep-20 3:29 
GeneralRe: How to create a method in a User control Pin
Member 147923936-Sep-20 6:37
MemberMember 147923936-Sep-20 6:37 
GeneralRe: How to create a method in a User control Pin
Ralf Meier6-Sep-20 10:34
professionalRalf Meier6-Sep-20 10:34 
GeneralRe: How to create a method in a User control Pin
Member 147923936-Sep-20 17:25
MemberMember 147923936-Sep-20 17:25 
QuestionCannot Create and Return an Instance of a Class Pin
Liagapi3-Sep-20 22:52
MemberLiagapi3-Sep-20 22:52 
AnswerRe: Cannot Create and Return an Instance of a Class Pin
Richard Deeming3-Sep-20 23:05
mveRichard Deeming3-Sep-20 23:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.