c# - Error using unity in mapping objects in MVC -


I see a problem in using Unity in the controller constructor. Here are the details -

In the unit configuration (unity.config) - here's what I am doing -

  container.RegisterType & lt; ISessionWrapper, SessionWrapper & gt; ()  

In the Controller Creator

  Public OnboardingController (ISessionWrapper sessionwrapper) {SessionWrapper = sessionwrapper; }  

SessionBrapper

Public Interface EsSespar {string brand {get; Set; } // string cranation culture {receive; Set; }}

  Public class session: Essentials {public string brand {get; Set; }}  

There was an error in doing this

No parameter-defined manufacturer for this object is defined. Description: An uncontrolled exception occurred during execution. Current Web Request Please review the stack trace for more information about the error and where it originated from the code. Exception Description: System.MissingMethodException: There is no parameter label constructor defined for this object.

Source Error: An unrestricted exception was generated during the execution of existing web requests. Exceptions about the origin and location of the exception can be identified using the exception stack trace. ****

When I change the Controller Constructor definition, then it's all working well. Public onboardingController (former): This (new SessionWrapper ()) {//}

You have to use custom to solve the examples of your controller classes using Unity. ControllerFactory used by default MVC requires that controller classes is a parameterless manufacturer

looks like a custom ControllerFactory

using unity
  public class UnityControllerFactory:. DefaultControllerFactory {Personal Read Only IUnityContainer _container; Public Unity Controller Editor (IUNTT Container) {_Container = Container; } Protected override IController GetControllerInstance (RequestContext requestContext, type controllerType) {if (controllerType = null!) {Return _container.Resolve (controllerType) as IController; } Else {return base.GetControllerInstance (requestContext, Controller type); }}}  

The application starts (Normally in Global.asax) you register your ControllerFactory in the MVC order following the code

  on the container. // Start your Unity Container Var Factory = New Unity Controller Feature (Container); ControllerBuilder.Current.SetControllerFactory (factory);  

Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -