Asp.net web api 已将Autofac类型注册为单个实例,但每次API调用都会实例化新实例

Asp.net web api 已将Autofac类型注册为单个实例,但每次API调用都会实例化新实例,asp.net-web-api,singleton,autofac,Asp.net Web Api,Singleton,Autofac,将ASP.NET API与Autofac一起使用,尝试在web API中注册单个实例 containerBuilder.RegisterType<SomeService>().As<ISomeService>().SingleInstance(); 我希望在整个应用程序生命周期中只实例化一次,但每次API调用都会创建一个新实例。我做错了什么?某个存储库未注册为单个实例。将SomeRepository注册为单个实例。您是否仔细检查了在连接容器时,SomeService的注

将ASP.NET API与Autofac一起使用,尝试在web API中注册单个实例

containerBuilder.RegisterType<SomeService>().As<ISomeService>().SingleInstance();

我希望在整个应用程序生命周期中只实例化一次,但每次API调用都会创建一个新实例。我做错了什么?

某个存储库未注册为单个实例。将SomeRepository注册为单个实例。

您是否仔细检查了在连接容器时,
SomeService
的注册是否未被覆盖?是否将
SomeRepository
注入了其他类?
containerBuilder.RegisterType<SomeRepository>().As<ISomeRepository>();
public class SomeService : ISomeService
    {
        private readonly ISomeRepository someRepository;

        public AppSettingService(ISomeRepository someRepository)
        {
            this.someRepository= someRepository;
        }
        ...