I've got classes and interfaces like bellow.
public interface IOffer
{
...
}
public class SomeOffer: IOffer
{
...
}
public interface IOfferManager<T>
{
...
}
public class OfferManager<T> : IOfferManager<T> where T : IOffer
{
...
}
factory class:
public OfferManager<IOffer> CreateOfferManager(int offerType)
{
switch (offerType)
{
case 0:
{
return _kernel.Get<IOfferManager<SomeOffer>>("SomeOffer");
//expected OfferManager<SomeOffer>;
}
...
}
}
Method CreateOfferManager(int offerType)
return error -> Cannot implicitly convert type IOfferManager<SomeOffer> to OfferManager<IOffer>
. An explicit conversion exists (are you missing a cast?)
And the question is why it gives me back an error if SomeOffer
is IOffer
? I can't resolve this problem. I've tried different type of returned value. Did I make a mistake in classes and interfaces construction? I have no idea why it doesn't work and how to do this differently. What is the best solution in this case?