logo
down
shadow

Autofac and WebAPI - Default constructor error


Autofac and WebAPI - Default constructor error

By : Pairtho
Date : November 21 2020, 01:01 AM
hop of those help? If you have your api controllers in a different assembly than your web project, then you need to need to tell Autofac where to find your controllers with changning:
code :
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.RegisterApiControllers(typeof(MyController).Assembly);


Share : facebook icon twitter icon
WebApi / AutoFac and an iDependencyResolver error

WebApi / AutoFac and an iDependencyResolver error


By : Jørgen Zakariassen
Date : March 29 2020, 07:55 AM
wish help you to fix your issue In addition to your resolver, you are going to need a controller factory, I don't have expereince creating a controller factory for autofac (my experience is with windsor), but it should be straight forward. You want to use configuration.DependancyResolver like so:
code :
configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
ControllerBuilder.Current.SetControllerFactory(yourfactory);
AutoFac Controller does not have a default constructor

AutoFac Controller does not have a default constructor


By : Hieu
Date : March 29 2020, 07:55 AM
help you fix your problem Hi I want to switch from Ninject to AutoFac but I'm having some problems. Error is: , Found it:
code :
// Set the dependency resolver for Web API.
var webApiResolver = new AutofacWebApiDependencyResolver(container);
GlobalConfiguration.Configuration.DependencyResolver = webApiResolver;
AutoFac with WebApi, Still looking for parameter less constructor

AutoFac with WebApi, Still looking for parameter less constructor


By : user3562062
Date : March 29 2020, 07:55 AM
This might help you You are trying to register your modules after the container has built.
You need to move the call
code :
RegisterModules(builder);
RegisterModules(builder);
IContainer container = builder.Build();
var builder = new Autofac.ContainerBuilder();
builder.RegisterControllers(typeof(WebApiApplication).Assembly).PropertiesAutowired();
builder.RegisterApiControllers(typeof(WebApiApplication).Assembly).PropertiesAutowired();
builder.RegisterModule(new RepositoryModule());
builder.RegisterModule(new ServiceFacadeModule());
builder.RegisterModule(new RepositoryModule());
builder.RegisterModule(new MappingModule());
builder.RegisterModule(new DomainModule());
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
WebApi DI Autofac - Make sure that the controller has a parameterless public constructor

WebApi DI Autofac - Make sure that the controller has a parameterless public constructor


By : Jose Velazquez
Date : March 29 2020, 07:55 AM
should help you out As there are quite a few upvotes on this question without any answers yet and I don't exactly remember how I made it work but I want to share the latest technique that has been working perfectly in many projects.
1) This is how I register my generic repsoitory and unit of work
code :
 builder.RegisterType(typeof(YourContextInRepository));
 builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
 builder.RegisterGeneric(typeof(UnitOfWork<>)).As(typeof(IUnitOfWork<>));
// Set the dependency resolver for Web API.
var webApiResolver = new AutofacWebApiDependencyResolver(container);
GlobalConfiguration.Configuration.DependencyResolver = webApiResolver;
// Set MVC DI resolver to use our Autofac container
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
private IUnitOfWork<Listing> _uow;
public SearchController(IUnitOfWork<Listing> uow)
{
    _uow = uow;
}
MVC 4 with WebAPI 2 does not have a default constructor error

MVC 4 with WebAPI 2 does not have a default constructor error


By : Raju Basak
Date : March 29 2020, 07:55 AM
like below fixes the issue Drax,
You shouldn't assign your DependencyResolver to the GlobalConfiguration when creating the kernel at that point. The reason is because the Start() method usually runs on WebActivator which kicks-in before even the ASP.NET WebAPI subsystem or your Application starts up.
Related Posts Related Posts :
  • ASP.NET get cell from DataRow in a datatable?
  • how can I use a Microsoft Account to authenticate to my website
  • Unable to start debugging on the web server. Unable to connect to the webserver
  • Not able to connect to cube
  • PDF creation using itextsharp is not working in client's server
  • Date field does not display the value in Chrome browser
  • Get Text of Hyperlink which is sitting inside template field in a gridview
  • how to scale image in email body?
  • FormAuthentication not working
  • Using Entity Framework constructors in derived classes
  • Code first database not being created from model
  • Loading external DLL into WinDBG
  • Pass JSON data to strongly typed partial view in ASP.NET
  • ASP.NET MVC 4 Application w/ Areas apps suffering horrible render times
  • view sections cause problems if not rendered in layout
  • Modifying code in a website on IIS
  • RouteConfig triggers 500 error when refreshing page
  • Is it possible to change the query string value
  • MetroUI buttoon server side Click Event
  • Change default idseparator in .Net 3.5?
  • Placing DataBound Drop Down List into TableCell
  • MVC 5 AspNet Identity - Value cannot be null. Parameter name: source
  • Save the value of Dynamically created textbox
  • asp.net identity membership saving both email and username for a user
  • IIS Manager Error
  • Grid dont have data Kendo UI and AngularJS in ASP.NET MVC
  • Project stops working after installing signalr
  • While querying with linq , Max function retrieves upto '9' if more than 9 values in the list
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org