Ich verwende Unity-Container. Ich habe meine Klasse zu IOC-Container registrieren. Wenn ich versuche, Instanz der Auth-Klasse zu erstellen, erhalte ich folgende Ausnahme: Ausnahme ist: InvalidOperationException - Der aktuelle Typ log4net.ILog ist eine Schnittstelle und kann nicht erstellt werden. Vermissen Sie ein Typ-Mapping?Ausnahme ist: InvalidOperationException - Der aktuelle Typ log4net.ILog ist eine Schnittstelle und kann nicht erstellt werden. Vermissen Sie ein Typ-Mapping?
Bitte lassen Sie mich wissen, wenn ich etwas falsch mache?
Mein Code:
using Unity;
Public Main()
{
private readonly IUnityContainer container;
public override void Instantiate()
{
container.RegisterSingleton<IAuthentication, Auth>("Auth");
}
public Authenticate()
{
var instance = container.Resolve<IAuthentication>("Auth");**//Getting exception here**
}
}
Auth Klasse:
public class Auth: IAuthentication
{
private readonly ILog log;
private IImpID impIDobj;
public Auth(ILog log, IImpID impIDobj)
{
this.impIDobj= impIDobj;
this.log = log;
}
public Auth()
: this(LogManager.GetLogger("Auth"), new CAuth())
{
}
public Authenticate()
{
impIDobj.Authenticate(data);
//Some logics
}
}
Voll Ausnahme: Ausnahme ist: InvalidOperationException - Der aktuelle Typ, log4net.ILog, ist eine Schnittstelle und kann nicht aufgebaut werden. Vermissen Sie eine Typzuordnung Zum Zeitpunkt der Ausnahme war der Container: Auflösen von Auth.IAuthentication [], (keine) Auflösen von Auth.IAuthentication, Auth Auflösen von ImpID.Auth, Auth Auflösen des Parameters 'log' von Konstruktor ImID.Auth (log4net.ILog log, IImpID impIDobj) Auflösen log4net.ILog, (keine) –
Wenn Sie weitere Informationen haben, dann bearbeiten Sie die Frage, nicht in einen Kommentar. – juharr
Wo haben Sie Ihre Protokollierungskomponente (n) mit dem Container registriert? – Amy