Good afternoon,
I'm trying to create dependency injection in Web Api, but I'm not getting it, I get the following error:
SimpleInjector.DiagnosticVerificationException HResult = 0x80131500 Message = The configuration is invalid. The following diagnostic warnings were reported: - [Lifestyle Mismatch] BracoService (Singleton) depends on Bank (Transient). - [Lifestyle Mismatch] CabecaService (Singleton) depends on Bank (Transient). - [Disposable Transient Component] Bank is registered as transient, but implements IDisposable.
Global.asax.cs:
using BecomexTeste.Service;
using SimpleInjector;
using SimpleInjector.Integration.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
namespace BecomexTeste
{
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
var container = new Container();
container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();
container.Register<IBracoService, BracoService>(Lifestyle.Singleton);
container.Register<ICabecaService, CabecaService>(Lifestyle.Singleton);
container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
container.Verify(); <----- O ERRO ESTÁ AQUI ----->
GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
}
}
}