小编unh*_*tle的帖子

如何在 Winform .net core 上使用 MediatR

我有一个 .net 核心 winform 应用程序,正在实现 n 层架构(ApplicationLayer(winform)、BLL、DAL)

已安装 MediatR 和 MediatR.Extensions.Microsoft.DependencyInjection

我目前正在关注这个网站:

https://dotnetcoretutorials.com/2019/04/30/the-mediator-pattern-part-3-mediatr-library/

我把这段代码放在哪里

public void ConfigureServices(IServiceCollection services)
{
    services.AddMediatR(Assembly.GetExecutingAssembly());
    //Other injected services. 
}
Run Code Online (Sandbox Code Playgroud)

我试过像这样把它放在 Main() 上:

    static class Program
{
    /// <summary>
    ///  The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main(IServiceCollection services)
    {
        services.AddMediatR(Assembly.GetExecutingAssembly());
        services.AddTransient<IApplicationHandler, ApplicationHandler>();

        Application.SetHighDpiMode(HighDpiMode.SystemAware);
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
}
Run Code Online (Sandbox Code Playgroud)

它给了我这个错误

程序不包含适合入口点的静态“Main”方法

c# dependency-injection winforms .net-core mediatr

2
推荐指数
1
解决办法
172
查看次数

标签 统计

.net-core ×1

c# ×1

dependency-injection ×1

mediatr ×1

winforms ×1