Die Einheit Der Typ nicht über einen zugänglichen Konstruktor

Ich habe vor kurzem angefangen mit unity und Es scheint zu funktionieren gut, außer für ein Platz... ich habe einige suchen, aber ich habe nichts gefunden das ich anwenden kann um meinen code.

Hier ist der code zum registrieren der Typen:

Container.RegisterType<IVsoCommunicator, VsoCommunicator>();
Container.RegisterType<IIpxConnection, IpxCommunicator>();
Container.RegisterType<IConsentService, ConsentService>(new InjectionFactory(p => new ConsentService(p.Resolve<IIpxConnection>(), p.Resolve<IVsoCommunicator>())));
Container.RegisterType<ITimer, ConsentStatusPoller>(new InjectionFactory(p => new ConsentStatusPoller(p.Resolve<IConsentService>())));

Und die Ausnahme:

Resolution of the dependency failed, type = "UserManager.Services.ConsentStatusPoller", name = "(none)".
Exception occurred while: while resolving.

Exception is: InvalidOperationException - The type IConsentService does not have an accessible constructor.

-----------------------------------------------

At the time of the exception, the container was:

Resolving UserManager.Services.ConsentStatusPoller,(none)

Resolving parameter "consentService" of constructor UserManager.Services.ConsentStatusPoller(UserManager.Services.IConsentService consentService)

Resolving UserManager.Services.IConsentService,(none)

Was mache ich hier falsch? Zuerst dachte ich, dass ich etwas privat, aber das war nicht der Fall

Verändert die Registrierung:

Container.RegisterType<ISettingsConfiguration, SettingsConfiguration>();
Container.RegisterType<IUnitOfWork, UnitOfWork>();
Container.RegisterType<IVsoCommunicator, VsoCommunicator>();
Container.RegisterType<IIpxConnection, IpxCommunicator>();
Container.RegisterType<IConsentService, ConsentService>();
Container.RegisterType<ITimer, ConsentStatusPoller>();

Zustimmung service:

public interface IConsentService
{
    void GetConsentReplies();
    void GetConsentSmsUpdates();
}
public class ConsentService : IConsentService
{
    private readonly IIpxConnection _ipx;
    private readonly IVsoCommunicator _vso;

    public ConsentService(IIpxConnection ipx, IVsoCommunicator vso)
    {
        _ipx = ipx;
        _vso = vso;
    }

    public async void GetConsentReplies()
    {
    }

    private void UpdateLocationConsentSmsData(List<IncomingMessage> messages)
    {

    }

    private void SendConsentMessages(IEnumerable<IncomingMessage> messages)
    {


    }

    private void SaveIpxConsents(IEnumerable<createConsentResponse1> responses)
    {
    }

    public async void GetConsentSmsUpdates()
    {

    }

    private static void SaveConsentSmsUpdates(GetMessageStatusResponse resp)
    {

    }

}

Zustimmung poller:

public interface ITimer
{
    void Start(int interval);
}
public class ConsentStatusPoller : ITimer
{
    private readonly IConsentService _consentService;
    readonly Timer _tmr;

    public ConsentStatusPoller(IConsentService consentService)
    {
        _consentService = consentService;
        _tmr = new Timer();
        _tmr.Elapsed += _tmr_Elapsed;
    }

    void _tmr_Elapsed(object sender, ElapsedEventArgs e)
    {
        _consentService.GetConsentReplies();
        _consentService.GetConsentSmsUpdates();
    }



    public void Start(int interval)
    {
        _tmr.Interval = interval;
        _tmr.Start();
    }
}
Warum müssen Sie stellen Spritzguss-Fabrik für IConsentService. Alle erforderlichen Schnittstellen sind bereits registriert, so defaul Registrierung sollte gut sein und die Einheit aufgelöst wird, Sie automatisch. Haben Sie überprüft, ob eine Zustimmung service-Konstruktor ist public oder nicht?
Ich habe versucht den code zu ändern, wie gezeigt in der Frage jetzt. Es hat nicht funktioniert so. Die Zustimmung der Service-Klasse ist public und ist so die anderen Klassen, die beteiligt sind.
Der Fehler ist der gleiche, jetzt, Sie verändert die Registrierung? Auch, können Sie Ihre IConsentService und ConsentService Klassen
Ja, es ist der gleiche Fehler. Ich habe nicht den code in den Klassen als der Klasse haben 240 Zeilen und ich denke, es ist egal. Aber ich merkte beim schreiben dieser, dass mein Erster Schritt war die Erstellung der ITimer, aber vergessen zu ändern, der Ort, wo ich löse die ConsentStatusPoller zu verwenden ITimer statt. So nun der Fehler ist der gleiche, aber er sagt, Dass die ITimer nicht über einen zugänglichen Konstruktor. Die Linie Im sprechen über "var consentPoller = IoC.Beheben<ITimer>();"

InformationsquelleAutor user1842278 | 2014-02-27

Schreibe einen Kommentar