ASP.NET MVC 6 AspNet.Session Errors - Unable to resolve injected dependency?

I've been having a problem using the new Microsoft.AspNet.Session features in ASP.NET MVC 6 (vNext).

The associated error The error occurs when accessing all pages, including those that don't use the session features themselves. I'm using the beta4 version for everything, including all of my packages and my dnvm environment. The project is running on Visual Studio 2015 RC.

Here are some resources that might be important (if there's anything else anybody needs just comment):

I think it's a problem with the dependency injection for the session package (see first two lines of the stack trace) but after that I'm not sure what to do about it.

Upvotes: 0

Views: 256

Answers (1)

Kévin Chalet
Kévin Chalet

Reputation: 42110

Are you sure you've correctly registered the appropriate services in ConfigureServices?

public class Startup {
    public void ConfigureServices(IServiceCollection services) {
        services.AddOptions();
        services.AddSession();
    }

    public void Configure(IApplicationBuilder app) {
        app.UseSession();
    }
}

Note: you need to explicitly register the options services as you're using beta4 packages. This issue was fixed recently: https://github.com/aspnet/Session/commit/dab08ba7e90027a3bf1ef69f740427e93a310f09#diff-2990206dea5be4b3850cad8d4759d577R14

Upvotes: 1

Related Questions