Basic Controller Variables

  • If controller is related to central only i.e it contains dbCore only it should inherit from BaseAsyncController
  • If controller is related to Organisation also i.e it contains both dbCore and dbOrg it should inherit from BaseAsyncFOController
  • While inheriting Any Controller from BaseAsyncController or BaseAsyncFOController, it should initialise base controller with respective variables also.
  • eg For BaseAsyncFOController:
using System;
 
public class DataMaintenanceController : BaseAsyncFOController
{
    #region Constructor
    public DataMaintenanceController(
        CoreAccountingMasterEntities dbCore
        , OrgAccDBEntities dbOrg
        , IErrorLog ErrorLog
        , DBHelper DBHelper
        , IAuthServices AuthService
        //,... extra
        )
    : base(dbCore, AuthService, ErrorLog, dbOrg, DBHelper)
    {
        //..extra code
    }
    #endregion
}
  • eg For BaseAsyncController
using System;
 
public class DataMaintenanceController : BaseAsyncController
{
    #region Constructor
    public DataMaintenanceController(
        CoreAccountingMasterEntities dbCore
        ,IErrorLog ErrorLog
        ,IAuthServices AuthService
        //,.. extra
        )
    : base(dbCore, AuthService, ErrorLog)
    {
        //..extra code
    }
    #endregion
}
  • The Result controller must be inside autofac config/startup file in order to make it start automatically. File: App_start/AutoFacConfig.cs
  • Code to Init Controller:
  • builder.RegisterType<DataMaintenanceController>();//.InstancePerRequest();
  • If the controller already contains variable for dbCore or dbOrg or AuthService or ErrorLog or DBHelper, then we should rename that variable to matching variable name with our BaseAsyncFOController or BaseAsyncController.
  • Our Variable Name in BaseAsyncController and BaseAsyncFOController are:
  • _dbCore, _dbOrg, _AuthService, _ErrorLog, _DBHelper
  • Also Remove base Controller variable initialisation in derived controller.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.