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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:43:08+00:00 2026-05-29T08:43:08+00:00

Currently, my MVC 3 app has a dependency on a static class that is

  • 0

Currently, my MVC 3 app has a dependency on a static class that is initialized in the Application_Start() like this:

protected void Application_Start()
{
    MyDependency.Initialize();
}

With the static class looking more or less like the following:

public static class MyDependency
{
    public static void Initialize()
    {
        // Perform some I/O...
    }
}

This dependency is used in an attribute class, which comes with the caveat of having no run-time dependencies (hence the call to initialize in the Application_Start())

public class MyAttributeClass : ...
{
    public MyAttributeClass()
    {
        MyDependency.DoSomething(); //...
    }
}

Ultimately, other developers in our shop will have to use this API, and I’d like to see if there’s a way to get rid of the line in the Application_Start() (an extra line of code in the Global.asax is likely to be a forgotten step)

For instance, is there a way the MyDependency class can “hook” into the pipeline without the needing to edit the Global.asax?

  • 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-29T08:43:09+00:00Added an answer on May 29, 2026 at 8:43 am

    Use a static constructor in MyDependency. Here’s the MSDN explaining the functionality static constructors provide.

    By using a static constructor you should then be able to perform all the IO you need, as the constructor will be run before any static members are accessed.

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

Sidebar

Related Questions

I am building a .NET MVC app that has a page with a list
i have an asp.net mvc app that has a form that uploads a file.
I'm developing a web app with asp.net mvc 2. This app, has a controller
Currently, I have a Site.Master page for my MVC app that renders great when
I'm currently working on a reasonably simple MVC app which allows the user to
i'm totally noob to asp.net mvc and currently i'm writing an web app which
Currently ASP.NET MVC's OutputCache attribute has a huge downfall. If you want to cache
I'm currently creating an MVC application that will likely to expand to include a
I'm currently using DataAnnotations to validate my MVC 2 app. However, I've ran into
I'm working on an app (based on Spring as DI and MVC framework) that

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.