samedi 15 avril 2017

Create Instance for different class with different constractors

I have two classes with different constractores.
There is one parameter

    public TagService(IRepositoryAsync<Tag> tagRespository):base(tagRespository)
    {
        _tagRespository = tagRespository;
    }

There are two parameters.

        public AdsService(IRepositoryAsync<Ads> iadsRepository,IUnitOfWork unitOfWork):base(iadsRepository)
    {
        this._iadsRepository = iadsRepository;
        this._unitOfWork = unitOfWork;
    }

At the beginning, I used below to initialize the class.

            //services have different constractors
        Service = (TEntityService)System.Activator.CreateInstance(typeof(TEntityService), new object[] { _repository, _unitOfWork });

But, it will not work for only one parameter. Is there any better way for above scenario.

Aucun commentaire:

Enregistrer un commentaire