Korzystam z pewnego kursu pokazującego jak tworzyć mikroserwisy. Przy próbie uruchomienia kodu dostaję taki komunikat (pierwsze linijki to warningi dot. niekompatybilności pakietów):
C:\Users\Marcin\source\repos\Actio\src\Actio.Services.Activities>dotnet run --urls "http://*:5050"
C:\Users\Marcin\source\repos\Actio\src\Actio.Common\Actio.Common.csproj : warning NU1701: Package 'Microsoft.AspNet.WebApi.Core 5.2.4' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project. [C:\Users\Marcin\source\repos\Actio\src\Actio.Services.Activities\Actio.Services.Activities.csproj]
C:\Users\Marcin\source\repos\Actio\src\Actio.Common\Actio.Common.csproj : warning NU1701: Package 'Microsoft.AspNet.WebApi.WebHost 5.2.4' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project. [C:\Users\Marcin\source\repos\Actio\src\Actio.Services.Activities\Actio.Services.Activities.csproj]
C:\Users\Marcin\source\repos\Actio\src\Actio.Services.Activities\Actio.Services.Activities.csproj : warning NU1701: Package 'Microsoft.AspNet.WebApi.Core 5.2.4' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.
C:\Users\Marcin\source\repos\Actio\src\Actio.Services.Activities\Actio.Services.Activities.csproj : warning NU1701: Package 'Microsoft.AspNet.WebApi.WebHost 5.2.4' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.
C:\Users\Marcin\source\repos\Actio\src\Actio.Services.Activities\Actio.Services.Activities.csproj : warning NU1701: Package 'Microsoft.AspNet.WebApi.Core 5.2.4' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.
C:\Users\Marcin\source\repos\Actio\src\Actio.Services.Activities\Actio.Services.Activities.csproj : warning NU1701: Package 'Microsoft.AspNet.WebApi.WebHost 5.2.4' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.
C:\Users\Marcin\source\repos\Actio\src\Actio.Common\Actio.Common.csproj : warning NU1701: Package 'Microsoft.AspNet.WebApi.Core 5.2.4' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
C:\Users\Marcin\source\repos\Actio\src\Actio.Common\Actio.Common.csproj : warning NU1701: Package 'Microsoft.AspNet.WebApi.WebHost 5.2.4' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Using launch settings from C:\Users\Marcin\source\repos\Actio\src\Actio.Services.Activities\Properties\launchSettings.json...
Unhandled Exception: System.InvalidOperationException: Cannot resolve scoped service 'Actio.Common.Commands.ICommandHandler`1[Actio.Common.Commands.CreateActivity]' from root provider.
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteValidator.ValidateResolution(Type serviceType, IServiceScope scope, IServiceScope rootScope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
at Actio.Common.Services.ServiceHost.BusBuilder.SubscribeToCommand[TCommand]() in C:\Users\Marcin\source\repos\Actio\src\Actio.Common\Services\ServiceHost.cs:line 79
at Actio.Services.Activities.Program.Main(String[] args) in C:\Users\Marcin\source\repos\Actio\src\Actio.Services.Activities\Program.cs:line 10
Wygląda na to, jakby źle był zarejestrowany serwis lub jakby brakowało mi jakiejś paczki. Problem w tym, że robię praktycznie wszystko wg poradnika. Kod wygląda następująco (kolejno wg wywołanych linijek). Prosiłbym o pomoc.
namespace Actio.Services.Identity
{
public class Program
{
public static void Main(string[] args)
{
ServiceHost.Create<Startup>(args) // linia 10
.UserRabbitMq()
.SubscribeToCommand<CreateUser>()
.Build()
.Run();
}
}
}
public BusBuilder SubscribeToCommand<TCommand>() where TCommand : ICommand
{
var handler = (ICommandHandler<TCommand>) _webHost.Services // linia 79
.GetService(typeof(ICommandHandler<TCommand>));
_bus.WithCommandHandlerAsync(handler);
return this;
}
namespace Actio.Common.Commands
{
public class CreateActivity : IAuthenticatedCommand
{
public Guid Id { get; set; }
public Guid UserId { get; set; }
public string Category { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public DateTime CreatedAt { get; set; }
}
}
namespace Actio.Common.Commands
{
public interface IAuthenticatedCommand : ICommand
{
Guid UserId { get; set; }
}
}
namespace Actio.Common.Commands
{
/// <summary>
/// Marker interface
/// </summary>
public interface ICommand
{
}
}