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 7533501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:44:41+00:00 2026-05-30T05:44:41+00:00

When using Unity 2.0 for dependency injection within a web application, it appears that

  • 0

When using Unity 2.0 for dependency injection within a web application, it appears that user controls, pages, etc will all need make explicit calls to retrieve the container and “fetch” the dependencies … so using the annotations like [dependency] won’t offer any value. This is likely since the location of the container (application context, http context cache, etc.) is unknown in the web configuration.

Since Unity itself provides method interception, isn’t there a way to “tell” unity how to fetch the container correctly when you build your own web application? Rather than having to create base classes for page, etc.?

  • 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-30T05:44:43+00:00Added an answer on May 30, 2026 at 5:44 am

    The problem is that the WebForms Pages and Controls are not set up to allow for construction by dependency injection, so Unity never gets invoked at all unless the class invokes Unity itself. I’ve found the best pattern in these cases is to invoke the DI framework in the constructor via a Service Locator and then use annotations to mark dependency properties. Something like this:

    public MyPage()
    {
        // Injector is a wrapper class so you can change the underlying DI framework
        // later if necessary.
        Injector.Inject(this); 
    }
    
    [Dependency]
    public SomeService MyService {get;set;}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've literally just started using the Unity Application Blocks Dependency Injection library from Microsoft,
I am trying to learn about dependency injection and i'm using the unity application
I'm using the Unity dependency injection framework. I have two classes, that each take
I am thinking about using Microsoft Unity for my Dependency Injection tool in our
I'm using the MS Unity container to do dependency injection, but a Resolve is
We are using Microsoft Unity and dependency injection and so we have parametrised constructor
I'm using a UserNamePasswordValidator in WCF along with Unity for my dependency injection, but
Our project is using constructor-based Dependency Injection (we're using Unity as our container) and
I am using Unity for dependency injection and have the instance of a class
We are using Unity framework for Dependency injection. I am registerring two concrete implementations

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.