Using Unity, I am currently receiving this error message when attempting to resolve a type:
The current type, Onboard.UI.Services.IMessagingService, is an interface and cannot be constructed
Below, is the code found in my App.xaml.cs
file that is throwing this error.
UnityContainer
.RegisterType<IMessagingService, SessionMessagingService>("SessionMessageService")
var sessionStateNotifactionService =
UnityContainer
.Resolve <SessionStateNotificationService>("SessionMessageService");
I am trying to .RegisterType<>
on two types that share the same interface IMessageService
. If I remove the attempt at trying to register a named type, e.g. the ("SessionMessageService")
parameter, everything works well; however, I no longer have a way to distinguish between which implemenation of the interface I wish to use.
The error is thrown on the call to .Resolve
as the constructor for SessionStateNotificationService
looks like
// ... class
private IMessagingService _messagingService;
public SessionStateNotificationService(IMessagingService messagingService)
{
// ...
The attempt here is to be more generic about what implementations I can offer to the SessionStateNotificationService
.
There are a number of questions regarding this error on StackOverflow, namely:
However, that question arises out of that OP doing some odd things and the accepted answer isn't applicable to the above case (which really attempts to follow the Unity documentation).
What am I missing?