小编som*_*ame的帖子

AutoFac Controller没有默认构造函数

嗨,我想从Ninject切换到AutoFac,但我遇到了一些问题.错误是:

Controllers.API.Basic.AddressController'没有默认构造函数

我在启动时注册了这个:

var builder = new ContainerBuilder();
builder.RegisterControllers(Assembly.GetExecutingAssembly());
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

builder.RegisterType<AddressRepository>().As<IBaseRepository<Address>>();

builder.RegisterAssemblyModules(Assembly.GetExecutingAssembly());

IContainer container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
Run Code Online (Sandbox Code Playgroud)

这是我的控制器:

public class AddressController : GenericBaseController<Address>
{
    public AddressController(IBaseRepository<Address> repository)
        : base(repository)
    {
    }
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?这适用于Ninject.

c# autofac asp.net-web-api

5
推荐指数
1
解决办法
4266
查看次数

Run Nunit Console with net 5.0

Following situation:

I have a third party tool which executes the nunit-console.exe to run unit tests. I've switched the tests to dot net 5.0 as this is a new requirement in our company. Now when I run the nunit-console.exe (Version: NUnit Console Runner 3.12.0-beta2) in the console the same way the third party app does I get this error:

>E:\Nunit\netcoreapp3.1\nunit3-console.exe "C:\Tests\bin\Debug\net5.0\Tests.dll"
it was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '3.1.0' was not found.
  - …
Run Code Online (Sandbox Code Playgroud)

nunit-console .net-core

5
推荐指数
0
解决办法
1856
查看次数

.net webapi filepath作为参数

我想知道是否有可能以某种方式将一个亲戚filepath作为字符串发送到GET方法.

我的方法:

public HttpResponseMessage Get([FromUri] string fileName)

My route:
    config.Routes.MapHttpRoute(
    name: "MiscApiDownload",
    routeTemplate: "api/{controller}/download/{fileName}",
    defaults: new {action = "Download" }
);
Run Code Online (Sandbox Code Playgroud)

文件名就像"test.jpg"工作,但只要我有一个subdirexp."folder/test.jpg"该方法不再被发现.这是合乎逻辑的.问题是如果有一个很好的方法在URI中执行此操作.我不想在体内接受它.

c# asp.net-web-api

1
推荐指数
1
解决办法
3115
查看次数

标签 统计

asp.net-web-api ×2

c# ×2

.net-core ×1

autofac ×1

nunit-console ×1