Inhalte aufrufen

Profilbild

Controller Constructor Parameters

IOC Autofac Controller Constructor

  • Bitte melden Sie sich an, um eine Antwort zu verfassen.
5 Antworten zu diesem Thema

#1 Anil

Anil

    Newbie

  • Members
  • Punkt
  • 4 Beiträge

Geschrieben: 31 March 2014 - 19:37

I want to modify some Controllers for which i need to add few more parameters to the Constructor of the Controller. If I add more parameters, it won't work. Can you please suggest where do I need to map the parameters (for ioc) so that it works fine?



#2 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3801 Beiträge

Geschrieben: 31 March 2014 - 20:43

Objects auto resolved by autofac needs to be registered in \Presentation\SmartStore.Web.Framework\DependencyRegistrar.cs.


Marcus Gesing

Smartstore AG


#3 Anil

Anil

    Newbie

  • Members
  • Punkt
  • 4 Beiträge

Geschrieben: 01 April 2014 - 05:19

Thanks for the reply. Can you please share some code or any example?



#4 Anil

Anil

    Newbie

  • Members
  • Punkt
  • 4 Beiträge

Geschrieben: 01 April 2014 - 05:31

here is the original store controller - 

 
        public Store Controller (IStoreService store service, ISettingService setting service,
                                                           ILocalizationService localizationService, IPermissionService permission service)
        {
            this._storeService = store service;
            this._settingService = setting service;
            this._localizationService = localizationService;
            this._permissionService = permission service;
        }
 
 

After modification, it should look like - 

 

 public Store Controller (IStoreService store service, ISettingService setting service, ILocalizationService localizationService,
            IPermissionService permission service, ILocationService location service, ICountryService country service,
            IStateProvinceService state province service)
        {
            this._storeService = store service;
            this._settingService = setting service;
            this._localizationService = localizationService;
            this._permissionService = permission service;
            = this._locationService location service;
            this._countryService = country service;
            this._stateProvinceService = state province service;
        }
 
Any suggestions?


#5 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3801 Beiträge

Geschrieben: 01 April 2014 - 14:18

private readonly IStoreService _storeService;
private readonly ISettingService _settingService;
private readonly ILocalizationService _localizationService;
private readonly IPermissionService _permissionService;
private readonly ILocationService _locationService;
private readonly ICountryService _countryService;
private readonly IStateProvinceService _stateProvinceService;

public StoreController(IStoreService storeService,
	ISettingService settingService,
	ILocalizationService localizationService,
	IPermissionService permissionService,
	ILocationService locationService,
	ICountryService countryService,
    IStateProvinceService stateProvinceService)
{
	this._storeService = storeService;
	this._settingService = settingService;
	this._localizationService = localizationService;
	this._permissionService = permissionService;
	this._locationService = locationService;
	this._countryService = countryService;
	this._stateProvinceService = stateProvinceService;
}

ILocationService is unknown (not a build in service), so it needs to be registered as described above.

 


Marcus Gesing

Smartstore AG


#6 Anil

Anil

    Newbie

  • Members
  • Punkt
  • 4 Beiträge

Geschrieben: 01 April 2014 - 18:57

thanks, finally, I am able to make it work




Auch markiert mit einem oder mehrerer dieser Schlüsselwörter: IOC, Autofac, Controller, Constructor