Open Closed

How to use dynamic client with WinForms #1030


User avatar
0
dwoodard created

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.

  • ABP Framework version: v4.2.2
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:
  • Steps to reproduce the issue:

Is there an example of how to use the dynamic client with Winforms?

What do I do with the client Module class?


3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi @dwoodard

    I think there is no problem if Winforms can use the module system of abp. There is no example for now.

  • User Avatar
    0
    dwoodard created

    hi @dwoodard

    I think there is no problem if Winforms can use the module system of abp. There is no example for now.

    Thanks. Perhaps I am just don't know what to do. Following the documentation, I did the following:

    1. I created a FooBarHttpApiClientModule
    public class FooBarHttpApiClientModule : AbpModule
    
    1. I added the ConfigureServices method to it.
            public override void ConfigureServices(ServiceConfigurationContext context)
            {
                context.Services.AddHttpClientProxies(
                    typeof(FooBarApplicationContractsModule).Assembly,
                    RemoteServiceName
                );
    
                context.Services.Configure<AbpRemoteServiceOptions>(options =>
                {
                    options.RemoteServices.Default = new RemoteServiceConfiguration("https://localhost:44330");
                });
            }
    
    1. I created a FooBarService class
    public class FooBarService : ITransientDependency
    
    1. Now what? Do I instantiate the FooBarHttpApiClientModule? I assume I need to initiate DI, which I can do.
  • User Avatar
    1
    dwoodard created

    Okay, I have at least got a somewhat working example.

        static class Program
        {
    
            private static IHost _host;
            private static IAbpApplicationWithExternalServiceProvider _application;
    
            [STAThread]
            static void Main()
            {
                Application.SetHighDpiMode(HighDpiMode.SystemAware);
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
    
                //
                // Create host and application
                //
                _host = Host
                    .CreateDefaultBuilder(null)
                    .UseAutofac()
                    .UseSerilog()
                    .ConfigureServices((hostContext, services) =>
                    {
                        services.AddApplication<WmsHttpApiClientModule>();
                        services.AddScoped<Form1>();
                    }).Build();
                _application = _host.Services.GetService<IAbpApplicationWithExternalServiceProvider>();
    
    
    
                //
                // Startup
                //
                Log.Logger = new LoggerConfiguration()
    #if DEBUG
                    .MinimumLevel.Debug()
    #else
                    .MinimumLevel.Information()
    #endif
                    .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                    .Enrich.FromLogContext()
                    .WriteTo.Async(c => c.File("Logs/logs.txt"))
                    .CreateLogger();
    
                try
                {
                    Log.Information("Starting WinForms host.");
                    _host.StartAsync();
                    _application.Initialize(_host.Services);
    
                    var form1 = _host.Services.GetService<Form1>();
                    
                    Application.Run(form1);
    
                }
                catch (Exception ex)
                {
                    Log.Fatal(ex, "Host terminated unexpectedly!");
                }
                finally
                {
                    Log.CloseAndFlush();
                }
    
    
                //
                // Clean up after main form closes
                //
                _application.Shutdown();
                _host.StopAsync();
                _host.Dispose();
    
            }
        }
    
Made with ❤️ on ABP v9.1.0-preview. Updated on December 12, 2024, 07:15