I am creating an API and I want to expose an interface called IReportFields, I want the client to implement this class and basically get fields from whatever datasource (usually database).
Within my IReport interface I want to take in an instance of the IReportFields (could be more than one, in my app I have at least 4), then do whatever I need to do within that interface, usually it will be something like build report or whatever.
So for example:
public interface IReportField
{
ICollection<ReportField> GetFields();
}
There could be various type of report fields e.g. they could derive for 3 or 4 different database tables etc…
Then on my main interface I will:
public interface IReport
{
string GetReport(IReportField[] field);
}
Question:
IReportFields can have multiple implementations, i.e. many different types of fields, how do I call the method GetReport keeping in mind I am using Ninject, how do I wire my interfaces together?
//this bit is where I am stuck, how do I pass in the params as I dont want a hard dependancy on a class that requires me to get a report
IFieldReport field1 = new FieldImp1();
IFieldReport field2 = new FieldImp2();
var report = GetReport(feild1, field2);
You can use
Constructorinjection to have all wired upIFieldReportssuch as you have the wiring as follows:And you have a
ReportImpllike this:Please let me know if I got it wrong