Note that there are some explanatory texts on larger screens.

plurals
  1. POAutofac - Resolve Class derived from Generic
    text
    copied!<p>Having some problems getting Autofac to register my types.</p> <p>I have the following setup based on another stack overflow post. <a href="https://stackoverflow.com/questions/4776396/validation-how-to-inject-a-model-state-wrapper-with-ninject/4851953#4851953">Validation: How to inject A Model State wrapper with Ninject? </a></p> <p>My setup is as follows </p> <pre><code>public interface IValidator : IDependancy public abstract class Validator&lt;T&gt; : IValidator public class UserValidator : Validator&lt;AccountModel&gt; sealed class ValidationProvider : IValidationProvider { private readonly Func&lt;Type, IValidator&gt; _validatorFactory; public ValidationProvider(Func&lt;Type, IValidator&gt; validatorFactory) { _validatorFactory = validatorFactory; } ... </code></pre> <p>My Autofac config is</p> <pre><code>builder.RegisterType(typeof (ValidationProvider)).As&lt;IValidationProvider&gt;(); builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies()) .Where(t =&gt; t.BaseType==(typeof(Validator&lt;&gt;))).InstancePerDependency() .As&lt;IValidator&gt;(); builder.Register&lt;Func&lt;Type, IValidator&gt;&gt;(c =&gt; { var cc = c.Resolve&lt;IComponentContext&gt;(); return type =&gt; { var valType = typeof(Validator&lt;&gt;).MakeGenericType(type); return (IValidator) cc.Resolve(valType); // failing here }; }); </code></pre> <p>I can resolve everything except the Func constructor in the ValidationProvider class. The error I'm getting is</p> <p>The requested service 'Sw.Web.Validation.Validator`1[[SweepHelper.Web.Models.AccountModel, Sw.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' has not been registered. </p> <p>Can anyone point me in the right direction here?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload