Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PluginApplicationBuilder: System.NullReferenceException: 'Object reference not set to an instance of an object. #5

Open
yiyungent opened this issue Aug 22, 2021 · 1 comment
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@yiyungent
Copy link
Owner

using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using PluginCore.IPlugins;

namespace WebSocketDemoPlugin
{
    public class WebSocketDemoPlugin : BasePlugin, IStartupXPlugin
    {
        public override (bool IsSuccess, string Message) AfterEnable()
        {
            Console.WriteLine($"{nameof(WebSocketDemoPlugin)}: {nameof(AfterEnable)}");
            return base.AfterEnable();
        }

        public override (bool IsSuccess, string Message) BeforeDisable()
        {
            Console.WriteLine($"{nameof(WebSocketDemoPlugin)}: {nameof(BeforeDisable)}");
            return base.BeforeDisable();
        }

        public void ConfigureServices(IServiceCollection services)
        {

        }

        public void Configure(IApplicationBuilder app)
        {
            var webSocketOptions = new WebSocketOptions()
            {
                // KeepAliveInterval - 向客户端发送 "ping" 帧的频率,以确保代理保持连接处于打开状态。 默认值为 2 分钟。
                KeepAliveInterval = TimeSpan.FromSeconds(120),
            };
            app.UseWebSockets(webSocketOptions);




        }

        public int ConfigureOrder
        {
            get
            {
                return 2;
            }
        }

        public int ConfigureServicesOrder
        {
            get
            {
                return 2;
            }
        }
    }
}

当执行 _components[c](app)System.NullReferenceException: 'Object reference not set to an instance of an object.'

_components[0] 不为 null, 是内部,当 _components[0]() 执行 Func<RequestDelegate, RequestDelegate> 委托时,才报错

image

@yiyungent yiyungent added the bug Something isn't working label Aug 22, 2021
@yiyungent
Copy link
Owner Author

猜测,ApplicationBuilder 还是需要 IServiceProvider ,可能需要什么 Service,

但奇怪的是,之前做过的实验, IPluginFinder 却可以正常从 MiddlewareInvokeAsync 方法上,通过依赖注入获取

@yiyungent yiyungent added the help wanted Extra attention is needed label Aug 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant