Skip to content

Commit

Permalink
Merge pull request #18 from enisn/feature/controller-property-activators
Browse files Browse the repository at this point in the history
♻️Set controller context in ControllerFactory
  • Loading branch information
enisn authored Dec 9, 2021
2 parents d8949f5 + 5b3ab75 commit 4804b40
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/DotNurse.Injector.AspNetCore/DotNurseControllerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,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;
Expand All @@ -22,7 +24,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;
}

Expand Down

0 comments on commit 4804b40

Please sign in to comment.