I need to create a WS with IoC.
The code looks like this:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class WSI : System.Web.Services.WebService
{
private readonly ICrypto _crypto;
public WSI(ICrypto crypto)
{
_crypto = crypto;
}
[WebMethod]
public string HelloWorld()
{
return _crypto.Encrypt("Hello World");
}
}
The SimpleInjector startup file looks like this:
public static void Initialize()
{
var container = new Container();
container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();
InitializeContainer(container);
container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
container.Verify();
GlobalConfiguration.Configuration.DependencyResolver =
new SimpleInjectorWebApiDependencyResolver(container);
}
private static void InitializeContainer(Container container)
{
container.Register<ICrypto, Crypto>();
}
When I run I get the error:
System.MissingMethodException: Nenhum construtor sem parâmetros foi definido para este objeto.
em System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
em System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
em System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
em System.Activator.CreateInstance(Type type, Boolean nonPublic)
em System.Activator.CreateInstance(Type type)
em System.Web.Services.Protocols.ServerProtocol.CreateServerInstance()
em System.Web.Services.Protocols.WebServiceHandler.Invoke()
em System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()