Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Simple Injector版本3.0.0中定义DefaultScopedLifestyle?_C#_Dependency Injection_Inversion Of Control_Simple Injector - Fatal编程技术网

C# 如何在Simple Injector版本3.0.0中定义DefaultScopedLifestyle?

C# 如何在Simple Injector版本3.0.0中定义DefaultScopedLifestyle?,c#,dependency-injection,inversion-of-control,simple-injector,C#,Dependency Injection,Inversion Of Control,Simple Injector,我在一个使用simple injector的项目中使用依赖项注入,它工作得很好,直到我需要定义一种生活方式来解决特定版本中的依赖项时,3.0.0(我使用此版本是因为我使用的是visual studio 2010) 在官方文档中,它说我可以使用以下代码行定义依赖项的生活方式: container.Register<IService, RealService>(Lifestyle.Scoped); 但是在这个版本中,我找不到AsyncScopedLifestyle类或其变体 如何设置D

我在一个使用simple injector的项目中使用依赖项注入,它工作得很好,直到我需要定义一种生活方式来解决特定版本中的依赖项时,3.0.0(我使用此版本是因为我使用的是visual studio 2010

在官方文档中,它说我可以使用以下代码行定义依赖项的生活方式:

container.Register<IService, RealService>(Lifestyle.Scoped);
但是在这个版本中,我找不到
AsyncScopedLifestyle
类或其变体


如何设置
DefaultScopeLifestyle
,或者直接在依赖项中设置它?

AsyncScopedLifestyle
的v3等价物是:

这种生活方式位于城市

此软件包要求您运行.NET 4.5或更高版本

如果您使用的是.NET 4.0,则必须使用LifetimeScope生活方式/ThreadScope生活方式并同步运行操作,或者在构建web应用程序时使用WebRequestLifestyle


您可以找到有关LifetimeScope和ThreadScopedLifestyle的更多信息。

要使用
新的ExecutionContextScope()
我必须从nuget下载SimpleInjector.Extensions.ExecutionContextScope包,对吗?但我遇到了以下错误:无法安装软件包“SimpleInjector.Extensions.ExecutionContextScoping 3.0.0”。您正试图将此程序包安装到以“.NETFramework,Version=v4.0”为目标的项目中,但程序包d不包含任何与该框架兼容的程序集引用或内容文件。这些文件是否直接等效?很抱歉,ExecutionContextScope从未支持.NET 4.0。您将不得不使用LIFTIMESCOPFILIFICATHOLYT/THEXPRECTION生活方式,并同步运行您的操作或使用WebQuestHistle生活方式来构建Web应用程序。您应该认真考虑升级。Visual Studio 2017社区版对小型组织免费。没有人使用VS2010。@William:您可以找到有关LifetimeScope和ThreadScopedLifestyle的更多信息。
container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();
container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();