jeudi 18 mai 2017

How to create an instances from all classes that implement generic interface that inherite from another generic Interface with reflection in C# a

How do i create an instances of classes that implement generic interface that inherite from another generic Interface using reflection in C# I need to get the imlemantation of : BarcodeTestHelper and BarcodeRepository and create the instance of them

My model:

public interface ITestData{}
public class BarcodelData : ITestData
    {
        public int Id { get; set; }
}

My API:

public interface IBaseTestHelper<T> where T : ITestData {}
 public interface IBarcodeTestHelper : IBaseTestHelper<BarcodeTestData>

My Implemantaion :

public class BarcodeTestHelper : TestBaseHelper, IBarcodeTestHelper
 {
 private readonly IBarcodeRepository<BarcodeTestData> _barcodeRepository;
 public BarcodeTestHelper(IBarcodeRepository<BarcodeTestData>                                              
                                                      barcodeRepository) 
    {
        _barcodeRepository = barcodeRepository;
    }
  }
 public interface IBarcodeRepository<T> : IRepository<BarcodeTestData> where T : ITestData
{
    BarcodeTestData SaveBarcode(string xmlBarcode);

}

 public class BarcodeRepository :  IBarcodeRepository<BarcodeTestData>
{
   BarcodeTestData SaveBarcode(string xmlBarcode)
   {
      do save work
   }
}





Aucun commentaire:

Enregistrer un commentaire