Ejemplo n.º 1
0
        /// <summary>
        /// 调用注入的方法
        /// </summary>
        /// <param name="startupType"></param>
        /// <returns></returns>
        public Action GetConfigureDelegate(Type startupType)
        {
            MethodInfo info = startupType.GetMethod("Configure");

            ParameterInfo[] parameters = info.GetParameters();
            Object[]        obj        = new Object[parameters.Length];
            for (Int32 i = 0; i < parameters.Length; i++)
            {
                obj[i] = _provider.GetRequiredService(parameters[i].ParameterType);
            }
            return(() => { startupType.GetMethod("Configure").Invoke(_provider.GetRequiredService(startupType), obj); });
        }
Ejemplo n.º 2
0
        public void Run()
        {
            IApplicationBuilder application = serviceProvider.GetRequiredService <IApplicationBuilder>();
            IStartupLoader      start       = serviceProvider.GetRequiredService <IStartupLoader>();

            //注入中间件
            start.GetConfigureDelegate(startupType)();
            //注入服务
            start.GetConfigureServices(startupType)(serviceCollection);
            ITransferServer transfer =
                serviceProvider.GetRequiredService <IServerFactory>().Create();

            transfer.Start(new HostApplication(application.Build()));
        }