autofac

Autofac property injection is not working

若如初见. 提交于 2019-12-11 13:27:46
问题 i am trying to use autofac for prism. Used bootstraper project link is bellow. autofac is passes depened object when i used as contructor parameter. but it's not passes when i use as property with a import attribute. https://bitbucket.org/stmu/prism.aufofacextension/src it's not a prism question. autofac is not inject properties. what is my mistake? how to solve this? thanks. 回答1: On your RegisterType calls, you most likely need to add .PropertiesAutowired() . 来源: https://stackoverflow.com

None of the constructors found can be invoked with the available services and parameters Autofac

丶灬走出姿态 提交于 2019-12-11 12:15:08
问题 I have read and coding follow example: http://timschreiber.com/2015/01/14/persistence-ignorant-asp-net-identity-with-patterns-part-1/ But that example used Unity for DI, but i'm used Autofac for ID, when i try run my project i have the following error: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'App.Front.Controllers.HomeController' can be invoked with the available services and parameters: Cannot resolve parameter 'Microsoft

Autofac - handle multiple requests in ASP.Net MVC 3

别等时光非礼了梦想. 提交于 2019-12-11 11:22:43
问题 I am new to Autofac and IoC so now I try to build my firs ASP.NET MVC 3 application with IoC. Here with this code I try manually to register ProductController (in Global.asax). protected void AutofacIocRegistration() { var builder = new ContainerBuilder(); //PRODUCT CONTROLLER var registration = builder.Register(c => new ProductsController(c.Resolve<IProductRepository>())); builder.RegisterType<ProductsController>().InstancePerHttpRequest(); SqlProductsRepository productRepository = new

error constructor controller MvC 4

让人想犯罪 __ 提交于 2019-12-11 10:19:33
问题 public partial class RegistrationController : Controller { private readonly IPartnerRepository _partnerRepository; public RegistrationController(IPartnerRepository partnerRepository) { _partnerRepository =partnerRepository; }} I use autoface to the dependancy injection and i have this error: ` No parameterless constructor defined for this object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information

How to use Autofac to inject decorator of a class in one constructor and the class itself in another?

岁酱吖の 提交于 2019-12-11 06:58:18
问题 I have an IoCConfig where in the RegisterDependencies method first all Services (same assembly as ServiceBase ) are registered, except for one service and one class called LastActivityUpdator and a decorator of this class called AnonymousUserLastActivityUpdator which both implement ILastActivityUpdator . The goals I want to accomplish is to have the decorator registered properly, which already works following this answer. And I also asked for a way to for one class ( UserService ) use the

Autofac optional/lazy dependencies

夙愿已清 提交于 2019-12-11 06:56:40
问题 If I put Lazy in constructor of my object, and X is not registered in container I got dependency resolution exception. Why am I getting this exception? I dislike it, because I cannot choose component at runtime. Example usecase: class Controller { public Controller(Lazy<A> a, Lazy<B> b) { /* (...) */ } Lazy<A> a; Lazy<B> b; public IActionResult Get(){ if(someConfig) return Json(a.Value.Execute()); else return Json(b.Value.Execute()); } } To do so I need to register both components A an B. My

Autofac + WCF REST 4.0

旧城冷巷雨未停 提交于 2019-12-11 06:51:30
问题 I am building a WCF 4.0 REST service and want to use Autofac as DI container. Apparently, I want to be able to call a parameterized constructor of the service class (service contract implementation), which accepts a bunch of interfaces to work with. Those interfaces are to be registered within Autofac container and I want them resolved and used when creating an instance of my service class (instead of calling not parameterized constructor, which is default). There is similar problem with MVC

Error: Make sure that the controller has a parameterless public constructor (Autofac, WebApi2, & Onion Architecture)

旧街凉风 提交于 2019-12-11 06:19:46
问题 OK, I am getting the familiar error: An error occurred when trying to create a controller of type 'UserController'. Make sure that the controller has a parameterless public constructor. ---> System.ArgumentException: Type 'Project.WebApi.Controllers.UserController' does not have a default constructor at System.Linq.Expressions.Expression.New(Type type) I am building a WebApi2 project (no MVC front end) that use Onion Architecture, putting most of my start-up code in App_Start of a Bootstrap

Autofac + MVC3 + Html.Action

。_饼干妹妹 提交于 2019-12-11 05:16:26
问题 I've got the same problem as in this question The error message is: A single instance of controller 'Search.Web.Controllers.AdvancedController' cannot be used to handle multiple requests. If a custom controller factory is in use, make sure that it creates a new instance of the controller for each request. Code in Global.asax: protected void Application_Start() { var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterType<AdvancedController>().InstancePerHttpRequest();

IoC using autofac and WCF IParameterInspector

被刻印的时光 ゝ 提交于 2019-12-11 04:38:42
问题 I'm trying to use autofac in the following scenario: A WCF service that, on every method call, receives connection details which it uses to open a DB connection. (i.e. public UserDTO GetUser(string dbUsername, string dbPassword, int userId) . Since opening a DB connection is common to all methods, I'd like to use an IParameterInspector to intercept every method call, extract the connection details, and initialize the connection. My problems are- 1. I don't know if (and how) I can inject the