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

The Archive Base Latest Questions

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

I have a class ( MyService ) that has a static property ( MyService.Context

  • 0

I have a class (MyService) that has a static property (MyService.Context) which represents a current context (which is specific to currently logged in user, so it changes).

What i’m trying to achieve i

ObjectFactory.Initialize(x =>
            {
                x.For<IMyService>().Use<MyInstance>(c => c.Use(MyService.Context));
            });

I.e. so that for every ObjectFactory.GetInstance<IMyService>() i get a reference to MyService.Context

Is that doable?

UPDATE

I can’t use a singleton pattern since MyService.Context changes depending on the user making a request (via HttpContext).

In the pseudo-code above lambda parameter c represents a SM context, so that i can return a custom result for each request. I’m aware of SM’s Intercept() but it’s fired after the object is constructed – not instead.

  • 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:37:32+00:00Added an answer on May 23, 2026 at 12:37 pm

    If you can work with a property there is the possibility to add a OnCreation method. The Action provided is executed against the instance just after creation:

    ObjectFactory.Initialize(x =>
            {
                x.For<IMyService>()
                 .Use<MyInstance>()
                 .OnCreation(x => x.Context = MyService.Context;
            });
    

    Or you can use lazy initialization and provide a Func to the Use method which is executed whenever a new instance is needed. This should execute in the right context:

    ObjectFactory.Initialize(x =>
            {
                x.For<IMyService>()
                 .Use<MyInstance>(() => new MyInstance(MyService.Context);
            });
    

    I hope one of this methods works for you.

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

Sidebar

Related Questions

I have a class that extends Application which has a lot of methods like:
I have A WCF service that has a class that inherits System.Web.Security.RoleProvider. In this
I have a class (let's call it MyService ) that accepts two dependencies in
I have an Activity that starts a Service. In my Activity: startService(new Intent(this, MyService.class));
I have class method that returns a list of employees that I can iterate
I have class with internal property: internal virtual StateEnum EnrolmentState { get { ..getter
I have class with a member function that takes a default argument. struct Class
I have a .Net service that has begun to refuse to start - the
Imagine I have a SearchService layer that has a method to search all cars
I have a service class implemented in Java 6 / Spring 3 that needs

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.