c# - Using Autofac Implemented with IDependencyResolver in MVC5 -


I'm running this once for a while: (

Where I I am stuck:

I have an MVC5 web application and I am using AutoFac for the IOC container under the hood, in fact I have a dependency for which I have a constructor Through parameters, but since I officially solve the autofack through the refolver interface, then give me the parameters I have tried to use a representative factory but I am still getting errors. I am sure that I have to mess something ....

  //////////////// My Interface // //////////////// Public Interface IConfiguration {string OwnerId {Get; set;} IDictionary & lt; string, string & gt; GetAllSettings (); string settings GetSettingByKey (string SettingsKey);} //////////////////// My Concrete Obze // /////////////////// Public Class Configuration: ICo Nfiguration {public representative configuration factory (string owner id); // This is based on the autofack wiki - Representative units public string owner iid {get; Set; } Public Dictionary & lt; String, string & gt; Get all the settings { Set;} Public Configuration (string owner id) {// Some logic for which owner needs} Public IDictionary & lt; String, string & gt; GetAllSettings () {// Some other logic is irrelevant for now} Public string GetSettingByKey (string settings) {// Some other logic is irrelevant for now}} ///////////////// // ///////////////// Registration Dependency in MVC ///////////////////////// ///////// var Builder = new containerbuilder (); builder.RegisterType & lt; Configuration & gt; () In form of. & Lt; IConfiguration & gt; (); // some other configurable var container = builder. Build (); // fixed dependency resolver for MVC5 dependency resistor .settersolar (new AutofacDependencyResolver (container)); //////////////////////////////////////////////// ///////// // Wherever I need IConfiguration in my MVC app // ///////////////////////////// /////////////////////////// var Own ID = GetOwnerId (); // where I need help var config = dependencyResolver.Current.GetService & lt; IConfiguration & gt; (); // How do I pass parameters (Owner ID) into my built-in AutoFac container? // I tried it, but this var configFactory = DependencyResolver.Current.GetService & lt; Func & lt; String, IConfiguration & gt; & Gt; (); Var config = configFactory.Invoke (ownerId);   

I do go to YSOD like this

No producer was found with 'AutoFac'. DefaultConstructorFinder 'Type' can be implemented with 'Services' and parameters available on' General 'configuration:' System.String ownerId 'parameter can not be solved by constructor'. Zero (system.String) '

Thanks guys in advance :)

I think you might have seen this link It is:

A suggestion that can solve your problem in this specific case, is doing it back to autofocuspensis resolor and calls the applicant to the native method, something like that (I do not know The syntax is correct):

  var rawContainer = (AutofacDependencyResolver) DependencyResolver.Current; RawContainer.ApplicationContainer.Resolve & lt; IConfiguration & gt; (New [] {ownerId});   

I do not have any right to code, but I have seen in this company that I work for a freedom method to wrap this code above that which is above it Some works: Public Static Class AutofacHelper {Public Stable T. Rijol & Lt; T & gt; (This Freedom Resolver Container, Parameter [] Paramas = Faucet) {var rawContainer = (AutofacDependencyResolver) DependencyResolver.Current; Return Raw Container App Container Resolve & lt; T & gt; ((IEnumerable & lt; Parameters & gt;) ParamsCtor); }}

And then you can call it normally through Dependency Resolver. Current

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -