简单注入器和.Net Core的依赖注入

时间:2018-10-11 15:23:48

标签: asp.net-core simple-injector masstransit

我在尝试激活“ PCNDmzWeb.Api.Services.MassTransitHostedService”时遇到错误“无法解析类型为“ MassTransit.IBusControl”的服务。””

我正在使用MVC Core的样板代码进行一些小的更改。在“配置服务”方法中,我具有以下内容:

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();

    _container.RegisterInstance<IBusControl>(
        Bus.Factory.CreateUsingRabbitMq(sbc =>
        {
            var host = sbc.Host("localhost", "dev", h =>
            {
                h.Username("guest");
                h.Password("guest");
            });
            sbc.ReceiveEndpoint(host, "job_results_queue", e =>
            {
                e.Consumer<StoreJobResultsConsumer>();
            });
        }));

    services.AddScoped<IHostedService, MassTransitHostedService>();

    IntegrateSimpleInjector(services);
}

似乎没有创建BusControl的实例。  该消息似乎表明在Microsoft Extensions Dependency Injection中发生了错误。我在做什么错了?

堆栈跟踪如下:

  

Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type   serviceType,类型ImplementationType,ISet 1 callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(Type serviceType, Type implementationType, ISet 1 callSiteChain)   Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor   描述符,类型为serviceType,ISet 1 callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateEnumerable(Type serviceType, ISet 1 callSiteChain)   Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type   serviceType,ISet 1 callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type serviceType, Type implementationType, ISet 1个callSiteChain,   ParameterInfo []参数,布尔值throwIfCallSiteNotFound)位于   Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(Type   serviceType,类型ImplementationType,ISet 1 callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor descriptor, Type serviceType, ISet 1 callSiteChain)   Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(Type   serviceType,ISet 1 callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, ISet 1 callSiteChain)   Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type   serviceType,ServiceProvider serviceProvider)   System.Collections.Concurrent.ConcurrentDictionaryExtensions.GetOrAdd [TKey,TValue,TArg](ConcurrentDictionary 2 dictionary, TKey key, Func 3 valueFactory,TArg arg)在   Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type   serviceType)在   Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider   提供者,输入serviceType)   Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService [T](IServiceProvider   提供者)   Microsoft.AspNetCore.Hosting.Internal.WebHost.d__26.MoveNext()   ---从上一个引发异常的位置开始的堆栈跟踪-   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()在   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)   Microsoft.AspNetCore.Hosting.WebHostExtensions.d__5.MoveNext()   ---从上一个引发异常的位置开始的堆栈跟踪-   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()在   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)   Microsoft.AspNetCore.Hosting.WebHostExtensions.d__4.MoveNext()   ---从上一个引发异常的位置开始的堆栈跟踪-   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()在   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)在Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost   主机)位于PCNDmzWeb.Api.Program.Main(String [] args)中   C:\ myapp \ PCNDmzWeb.Api \ Program.cs:第17行

0 个答案:

没有答案