aspnet / DependencyInjection

[Archived] Contains common DI abstractions that ASP.NET Core and Entity Framework Core use. Project moved to https://github.com/aspnet/Extensions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

get different objects in controller and service?

venyowong opened this issue · comments

I have a class:

    public class RequestContext
    {
        public CallContext CallingContext{get;set;}
        public string ActionName{get;set;}
    }

And I configured it in Startup.ConfigureServices:
services.AddScoped<HttpSession>();

Then I injected it into controller and service:
public HomeController(RequestContext requestContext, IService service)
public Service(RequestContext requestContext)

And I invoked these code in controller:
requestContext.ActionName = string.Format("{0}.{1}", this.RouteData.Values["controller"].ToString().ToLower(), this.RouteData.Values["action"].ToString().ToLower());

But I found requestContext.ActionName is null in service.

Oh no, I found my service is a singleton...