Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6091463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:19:51+00:00 2026-05-23T12:19:51+00:00

I want to dependency inject an attribute in ASP.NET MVC using Spring.Net, my attribute

  • 0

I want to dependency inject an attribute in ASP.NET MVC using Spring.Net, my attribute is something like this (note this is all pseudo code I’ve just typed in)…

public class InjectedAttribute : ActionFilterAttribute
{
    private IBusinessLogic businessLogic;

    public InjectedAttribute(IBusinessLogic businessLogic)
    {
        this.businessLogic = businessLogic;
    }

    public override void OnActionExecuting(ActionExecutedContext filterContext)
    {
        // do something with the business logic
        businessLogic.DoSomethingImportant();
    }
}

I’m using a controller factory to create the Controllers which are also injected with various business logic objects. I’m getting the controllers from the IoC container like this…

ContextRegistry.GetContext().GetObject("MyMVCController");

I’m configuring my Controllers like so passing in the business logic

<object name="MyMVCController" type="MyMVC.MyMVCController, MyMVC">
    <constructor-arg index="0" ref="businessLogic" />
</object>

Is there a way to configure the injection of the attributes? I don’t really want to put this into my attributes…

public class InjectedAttribute : ActionFilterAttribute
{
    private IBusinessLogic businessLogic;

    public InjectedAttribute(IBusinessLogic businessLogic)
    {
        this.businessLogic = ContextRegistry.GetContext().GetObject("businessLogic");
    }
    ....
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:19:51+00:00Added an answer on May 23, 2026 at 12:19 pm

    I’m configuring my Controllers like so passing in the business logic

    This defines controllers as singletons meaning that they will be reused among all requests which could be catastrophic. Ensure controllers are not defined as singletons:

    <object name="AnotherMovieFinder" type="MyMVC.MyMVCController, MyMVC" singleton="false">
        <constructor-arg index="0" ref="businessLogic" />
    </object>
    

    Now, this being said let’s go back to the main question about attributes.

    Because you want constructor injection in your filters you can no longer decorate any controllers or actions with them as attribute values must be known at compile time. You need a mechanism to apply those filters at runtime to controllers/actions.

    If you are using ASP.NET MVC 3 you could write a custom filter provider which will apply your action filter to desired controllers/actions by injecting dependencies into it.

    If you are using an older version you could use a custom ControllerActionInvoker.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Autofac. I want to inject a different implementation of a dependency based
I want to declare two beans and instantiate them using Spring dependency injection? <bean
I'm using StructureMap for dependency injection and I want to inject NHibernate sessions with
I'm using ASP.NET MVC 2 to implement a web service and I have a
I need the actual debug symbols from the released version of ASP.NET MVC 2
In my Spring MVC webapplication I want to mix xml based configuration with annotations:
I have a bean that i want to inject with a named list using
I'm using the July CTP of .Net RIA Services in an ASP.Net application with
I'm building an ASP.NET MVC application that uses a DDD (Domain Driven Design) approach
I want to remove dependency on the location of EAR file while deploying it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.