From 8a17b9095697b182971516f149287b6c3ee46305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enis=20Necipo=C4=9Flu?= Date: Thu, 9 Dec 2021 10:39:05 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=E2=99=BB=EF=B8=8FSet=20controller=20contex?= =?UTF-8?q?t=20in=20ControllerFactory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DotNurseControllerFactory.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/DotNurse.Injector.AspNetCore/DotNurseControllerFactory.cs b/src/DotNurse.Injector.AspNetCore/DotNurseControllerFactory.cs index 9db21e8..ed49274 100644 --- a/src/DotNurse.Injector.AspNetCore/DotNurseControllerFactory.cs +++ b/src/DotNurse.Injector.AspNetCore/DotNurseControllerFactory.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc; +using DotNurse.Injector.AspNetCore.Extensions; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Controllers; using System; using System.Collections.Generic; @@ -13,7 +14,9 @@ public class DotNurseControllerFactory : IControllerFactory private readonly IControllerActivator controllerActivator; private readonly IAttributeInjector attributeInjector; - public DotNurseControllerFactory(IControllerActivator controllerActivator, IAttributeInjector attributeInjector) + public DotNurseControllerFactory( + IControllerActivator controllerActivator, + IAttributeInjector attributeInjector) { this.controllerActivator = controllerActivator; this.attributeInjector = attributeInjector; @@ -22,7 +25,14 @@ public DotNurseControllerFactory(IControllerActivator controllerActivator, IAttr public object CreateController(ControllerContext context) { var controller = controllerActivator.Create(context); + + if (controller is ControllerBase controllerBase) + { + controllerBase.ControllerContext = context; + } + attributeInjector.InjectIntoMembers(controller, context.HttpContext.RequestServices); + return controller; } From 5b3ab756c745fed2f7db3121309154280ef10865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enis=20Necipo=C4=9Flu?= Date: Thu, 9 Dec 2021 12:45:44 +0300 Subject: [PATCH 2/2] Build fix at DotNurseControllerFactory --- src/DotNurse.Injector.AspNetCore/DotNurseControllerFactory.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/DotNurse.Injector.AspNetCore/DotNurseControllerFactory.cs b/src/DotNurse.Injector.AspNetCore/DotNurseControllerFactory.cs index ed49274..80cf5dc 100644 --- a/src/DotNurse.Injector.AspNetCore/DotNurseControllerFactory.cs +++ b/src/DotNurse.Injector.AspNetCore/DotNurseControllerFactory.cs @@ -1,5 +1,4 @@ -using DotNurse.Injector.AspNetCore.Extensions; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Controllers; using System; using System.Collections.Generic;