-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Hello, I the following part of the Program startup for the asp.net core mvc app:
var builder = WebApplication.CreateBuilder(args);
var services = builder.Services;
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.LoginPath = "/Account/Login";
options.LogoutPath = "/Account/LogOut";
options.AccessDeniedPath = "/Account/AccessDenied";
});
services.AddDistributedMemoryCache();
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
services.AddControllersWithViews();
services.AddHttpContextAccessor();
services.AddMvc();
var container = new Container();
services.AddSimpleInjector(container,
options =>
{
// I have there some registrations
container.Options.ResolveUnregisteredConcreteTypes = true;
container.Register<SessionVars>();
options
.AddAspNetCore()
.AddControllerActivation()
.AddViewComponentActivation()
.AddPageModelActivation()
.AddTagHelperActivation();
options.AddLogging();
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseSession();
app.UseHttpsRedirection();
var currentDirectory = Directory.GetCurrentDirectory();
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(currentDirectory, "MyCustomFolder")),
});
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Main}/{action=MainView}/{id?}");
// Init IOC
app.MapControllers();
app.Services.UseSimpleInjector(container);
container.Verify();
app.Run();Also I have the controller:
public class MyController
{
public class MyController(SessionVars sessionVars)
{
.....
}
.....
}
public class SessionVars
{
public SessionVars(ISession session)
{
....
}
....
}And I have a problem when container.Verify(); : The configuration is invalid. Creating the instance for type SessionVars failed. The constructor of type SessionVars contains the parameter with name 'session' and type ISession, but ISession is not registered. For ISession to be resolved, it must be registered in the container. The ISession is from namespace: Microsoft.AspNetCore.Http.
Package information:
"Microsoft.AspNet.Mvc" Version="5.2.7"
"SimpleInjector" Version="5.4.2"
"SimpleInjector.Integration.AspNetCore.Mvc" Version="5.5.0"
Metadata
Metadata
Assignees
Labels
No labels