C # .NET constructor overload issue

Consider a multi-level application in which the DataLayer has a certain class with all data access materials in it and above, that the business layer has a class that can accept a data object in the constructor, and also has other overloads. Example:

namespace Datalayer
{
    public class dataObject
    {
        // all the class here
    }
}  

namespace BusinessLayer
{
    public class busObject
    {
        busObject(){}
        busObject(Datalayer.dataObject parm) {/*do something with parm*/}
        busObject(int objectID) {/*go get the dataObject with the ID*/}
    }
}

The layers above (possibly the user interface layer) should not have a datalayer reference in this model. However, when creating ctors in a business layer, this is necessary. Can someone explain why?

I would prefer my ctors this way, but I don't want the datalayer link in the user interface layer. To get around this for today, I removed the last ctor and added a method per se to configure the object after instantiation:

Select(int objectID) {/*go get the dataObject with the ID*/}

- , , ?

+3
2

, ... , - . - ; , , .

: , . . , .

// in it own dll: Datalayer.Interfaces.dll
namespace Datalayer.Interfaces{
public interface IdataObject
{ // interface declaration }

namespace Datalayer {
public class dataObject: IdataObject
{// all the class here } }  

namespace BusinessLayer {
public class busObject : IdataObject {
  busObject(){} 
  busObject(IdataObject dataObject) {} 
  busObject(int objectID) {//go get the dataObject with the ID}
}}

- , . - , AutoMapper.

+1

DataLayer DI , DataLayer.

0

Source: https://habr.com/ru/post/1721898/


All Articles