New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Container fails on verification #622
Comments
This last statement makes little sense, because Simple Injector never injects |
@dotnetjunkie , ok, here's mu public class Startup
{
private readonly Container _container = new Container();
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddDbContext<DeviceContext>(o =>
{
o.UseSqlServer(@"[connstr]");
});
IntegrateSimpleInjector(services);
}
// This method gets called by the runtime. Use this method to configure the
// HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
InitializeContainer(app);
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseMvc();
}
private void IntegrateSimpleInjector(IServiceCollection services)
{
_container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.UseSimpleInjectorAspNetRequestScoping(_container);
services.EnableSimpleInjectorCrossWiring(_container);
}
private void InitializeContainer(IApplicationBuilder app)
{
// Allow Simple Injector to resolve services from ASP.NET Core.
_container.AutoCrossWireAspNetComponents(app);
_container.Register<IFoo, DeviceContext>(Lifestyle.Scoped);
_container.Register<IDeviceTypeService, DeviceTypeService>(Lifestyle.Scoped);
_container.Verify(VerificationOption.VerifyAndDiagnose);
}
} and here is the service: public class DeviceTypeService : IDeviceTypeService
{
private readonly IFoo _foo;
public DeviceTypeService(IFoo foo)
{
Guard.ArgumentNotNull(_foo, nameof(foo)); // this throws, if foo is null.
_foo = foo;
}
}
public interface IFoo { } VS shows me exception:
As soon as I remove |
Ooops. I am an Idiot. Sorry =( mistyped... |
I am using Simple Injector with ASP.NET Core. Cross-wiring is enabled and components are auto-cross-wired.
I registered EF's
MyDbContext
withAddDbContext
extension method, andMyDbContext
implementsIFoo
interface.I register service
MyService
which expectsIFoo
as a constructor parameter.When I call
Verify
on container insideInitializeContaner
method,MyService
is constructed and receivesnull
forIFoo
.The text was updated successfully, but these errors were encountered: