Click here to Skip to main content
15,919,879 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please check Dependency Injection correctly used in below code or need some changes

What I have tried:

C#

// Registration Model

public class RegistrationModel
{
  // Properties
}

//Interface

Public interface IRegistration
{
 string Insert(RegistrationModel _objReg);
}

// BL

public class RegistrationBL
    {
        IRegistration _iReg;
        public RegistrationBL(IRegistration _iRegistration)
        {
            this._iReg =_iRegistration;
        }

        public string Insert(RegistrationModel _objModel)
        {
            return _iReg.Insert(_objModel);
        }
}


  //DL

public class RegistrationConcrete : IRegistration
    {
       public string Insert(RegistrationModel _objReg)
      {
             // Insert statement Here
      }
} 

// My code in controller For DI

  public class RegistrationController : Controller
    {
       
        RegistrationBL _objRegBL;
        public RegistrationController()
        {
             
            _objRegBL= new RegistrationBL(new RegistrationConcrete());
        }
  }
Posted
Comments
Sinisa Hajnal 28-Nov-17 3:36am    
Consider changing RegistrationModel concrete class to interface (IModel or IRegistrationModel depending on how you want to use it) - that way you can create mock data for testing and decouple your IRegistration interface from concrete model class.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900