Having some problems getting Autofac to register my types.
I have the following setup based on another stack overflow post. Validation: How to inject A Model State wrapper with Ninject?
My setup is as follows
public interface IValidator : IDependancy
public abstract class Validator<T> : IValidator
public class UserValidator : Validator<AccountModel>
sealed class ValidationProvider : IValidationProvider
{
private readonly Func<Type, IValidator> _validatorFactory;
public ValidationProvider(Func<Type, IValidator> validatorFactory)
{
_validatorFactory = validatorFactory;
}
...
My Autofac config is
builder.RegisterType(typeof (ValidationProvider)).As<IValidationProvider>();
builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies())
.Where(t => t.BaseType==(typeof(Validator<>))).InstancePerDependency()
.As<IValidator>();
builder.Register<Func<Type, IValidator>>(c =>
{
var cc = c.Resolve<IComponentContext>();
return type =>
{
var valType = typeof(Validator<>).MakeGenericType(type);
return (IValidator) cc.Resolve(valType); // failing here
};
});
I can resolve everything except the Func constructor in the ValidationProvider class. The error I'm getting is
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.
Can anyone point me in the right direction here?