0

i'm trying to use Belgrade-SqlClient (Small async ADO.NET helper library)

in c# web api all is fine but when i try to register Icommand as a service

i got error:

System.ArgumentException: 'The service type ICommand is not supported. Parameter name: serviceType

this is my webapiconfig.cs where i add ICommand as service:

string Conn = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; ;
        config.Services.Add(typeof(ICommand), new Command(Conn));

and this is Icommand:

using System.Threading.Tasks;

namespace Belgrade.SqlClient
{
    public interface ICommand : IQueryMapper, IQueryPipe
    {
        Task Exec();
    }
}
4

1 回答 1

0

我想您正在使用config.Services作为 IServiceCollection。然后您可能需要使用AddTransient,如下所示:

config.Services.AddTransient<ICommand>(() => new Command(Conn))
于 2018-07-25T05:16:50.417 回答