Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an interface and class like this

C#
public interface ICustomerEx
{
   void Load(DataRow row);
}

public class Customer:ICustomerEx
{
   public string Name{get;set;}
   public string Address{get;set;}

   void Load(DataRow row)
   {
	Name = (string)row["name"];
	Address = (string)row["address"];
   }
}



Now I'm building this as a class library and add to another project as a reference.
In that project there's a class called UiCustomer that implements from the same refereced interface ICustomerEx
In this class it has its own property and load that property from its load method.

C#
public class UiCustomer:ICustomerEx
{
   public string Telephone{get;set;}

   void Load(DataRow row)
   {
	Telephone=(string)row["tele"];
   }
}


Now is there any way to implement my first class's(that build as a class library) Load method to load Ui project's properties after loading it's own properties by using like Dependency Injection.

eg.

C#
public class Customer:ICustomerEx
{
   public string Name{get;set;}
   public string Address{get;set;}

   void Load(DataRow row)
   {
	Name = (string)row["name"];
	Address = (string)row["address"];

	//Call load methods in other places that Interface implemented
   }
}
Posted

1 solution

What about having an additional property/field
C#
ICustomerEx _Inner;

whose value could be injected into the constructor, or set after construction.
Then in your Load() method, you could call its Load method:
C#
if (_Inner != null)
{
    _Inner.Load();
}
 
Share this answer
 

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