i have a legacy application that has WCF as its entry point and it dependency injects interface created in .net framework 4.5.1 project. i am trying to replace wcf layer with asp.net core and when i try to dependency inject using asp.net core's default DI i get
Exception is: InvalidOperationException - The current type, xxxx is an interface and cannot be constructed. Are you missing a type mapping?
I tried this with Asp.net core 2.2 with target framework 4.6.1 and also with asp.net core 2.1 where target framework is set to .net core 2.1
my DI setup in asp.net core looks like this
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddSingleton<ITradeBusinessService, TradeBusinessService>();
services.AddSingleton<IUnityContainer, UnityContainer>();
services.AddSingleton<ICommonDataRepository, CommonDataRepository>();
}
this service TradeBusinessService takes in IUnityContainer in constructor.
public TradeBusinessService(IUnityContainer objectContainer)
{
container = objectContainer;
commonRepository = container.Resolve<ICommonDataRepository>();
and when i try to resolve ICommonDataRepository i get the error above.
ICommonDataRepository is in a project that is targeting 4.5.1
any ideas what i am doing wrong here?