0

I have a generic interface which inherits from another generic interface from a third party library (which makes it impossible to use covariance and contravariance) .

Here is my code

public interface IFABaseAppService<TDto, TKey> 
         : ICrudAppService<TDto, TKey> where TDto : FABaseDto
{
}

I have another interface IUserAppService

public interface IUserAppService : IFABaseAppService<UserDto, Guid>
{
}

Then I have a base class which accepts IFABaseAppService<FABaseDto, Guid> in constructor as a parameter

public class FABaseStandardFormViewModel : FABaseViewModel
{
    public FABaseStandardFormViewModel(IFABaseAppService<FABaseDto, Guid> appService) : base(appService)
    {
    }
}

Then I have created a class which accepts IUserAppService in the constructor and passes it to the base class, but it is giving me the following error:

cannot convert from 'FinancialsAce.ApplicationServices.Common.IUserAppService' to 'FinancialsAce.ApplicationServices.IFABaseAppService<FinancialsAce.DataTransferObjects.FABaseDto, System.Guid>

1 Answer 1

1

This error message means that IFABaseAppService<UserDto, Guid> can not be converted to IFABaseAppService<FABaseDto, Guid> because IFABaseAppService is not declared as covariant relatively to TDto.

See more about covariance: Covariance and Contravariance (C#).

You can fix it by adding out keyword as shown below:

public interface IFABaseAppService<out TDto, TKey> ...
Sign up to request clarification or add additional context in comments.

1 Comment

Sir as i mentioned in my question i can't use covariance and contravariance because my interface is inherited from another generic interface from a third party library. when i add out it doesn't let me pass it to other interface,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.