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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:08:10+00:00 2026-06-01T12:08:10+00:00

I currently have a type that I inject into my controllers that’s used for

  • 0

I currently have a type that I inject into my controllers that’s used for getting and setting session data.

I use this so that I can obtain relevant session information as _sessionData.Username rather than using Session["username"].

I’d like to use this session information across all of my views and would previously have done this by making the SessionData members static instead of injecting the SessionData class into my controller.

I want to avoid using static members as well as having to pass the object to the view in each controller.

What patterns best suit this type of scenario? What do you do to solve this same problem?

  • 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-06-01T12:08:12+00:00Added an answer on June 1, 2026 at 12:08 pm

    Why not just use Session[“username”]? You can wrap the static call in an instance like this:

    public class MySessionClass
    {
        public string GetSessionValue(String value)
        {
            return Session[value];
        }
    }
    

    You gain the maintenance and flexibility of an instance that can then be mocked in a test without having to rewrite the Session class over again

    UPDATE

    As far as using your instance in your view, what is stopping you from writing a code-block and newing it up and using it? You should be able to write code against it like any other code nuggets in MVC. However, I would suggest against doing this as it defeats the purpose of tiering your architecture. You can either access the session directly, like you would with any HTML page, or you can pass it through as an object from your controller.

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

Sidebar

Related Questions

How can I modify this: /services/type/single_dwelling/ to this: /ajax/services/single_dwelling/development Currently I have: linkUrl =
I currently have the following code that retrieves data from the database and then
I currently have this type of code: private void FillObject(Object MainObject, Foo Arg1, Bar
I currently have a function: public static Attribute GetAttribute(MemberInfo Member, Type AttributeType) { Object[]
I have a complex type defined which doesn't currently contain any minOccurs restrictions. When
I have the following code currently: <DataTemplate DataType={x:Type vm:SectionViewModel}> <ScrollViewer> <ItemsControl ItemsSource={Binding ViewModels}> </ItemsControl>
Currently, I have some code as follows template<typename Type> Type* getValue(std::string name, bool tryUseGetter
I am currently working with .Net 2.0 and have an interface whose generic type
I currently have 4 textboxes which will be used to store an ip address.
We use a wrapper that is delivered to us by our client, into which

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.