I have a problem when my context does not register in my startup.cs
My full launch looks like
public class Startup
{
public void Configuration(IAppBuilder app)
{
var builder = new ContainerBuilder();
RegisterApiTypes(builder);
var config = new HttpConfiguration();
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration);
var container = builder.Build();
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
app.UseAutofacMiddleware(container);
app.UseAutofacWebApi(config);
app.UseWebApi(config);
}
private static void RegisterApiTypes(ContainerBuilder builder)
{
builder.RegisterType<Logger>()
.As<ILogger>()
.InstancePerRequest();
builder.RegisterType<ApplicationService>().As<IApplicationService>().InstancePerLifetimeScope();
builder.RegisterType<CardRepository>().As<ICardRepository>().InstancePerLifetimeScope();
builder.RegisterAssemblyTypes(Assembly.Load("MyApp.Data"))
.Where(t => t.Name.EndsWith("Repository"))
.AsImplementedInterfaces()
.InstancePerLifetimeScope();
}
}
My context class is nothing special
public class CustomContext:DbContext
{
public CustomContext() : base("DefaultConnection")
{
}
}
I am trying to enter context into a standard estate
public MyRepository(CustomContext context)
{
_context = context;
}
However the error is being caused
None of the constructors found with "Autofac.Core.Activators.Reflection.DefaultConstructorFinder" of type "MyApp.Data.Repository.MyRepository" can be called by the available services and parameters: \ r \ nPass the "MyApp" parameter. Data.CustomContext context of the 'constructor' Void.ctor (MyApp.Data.CustomContext) '. "
Has anyone else experienced this behavior?
source
share