0
我的Web應用程序使用Unity for DI。 webapp的另一部分使用MEF。代碼在單線程會話中正常工作。但只要我點擊來自兩個不同網絡會話(CHrome和FIrefox)的同一鏈接。我不確定這是循環引用循環問題還是線程問題......它在單個會話上工作得很好,只有在兩個不同會話中單擊相同鏈接時纔會出現此錯誤。MEF/Unity依賴關係解決方案在多個線程上失敗
我得到以下錯誤:
Server Error in '/' Application.
GetExportedValue cannot be called before prerequisite import 'MyApp.Core.Services.RuleService..ctor (Parameter="productService", ContractName="MyApp.Core.Services.IProductService")' has been set.
InvalidOperationException: GetExportedValue cannot be called before prerequisite import 'MyApp.Core.Services.RuleService..ctor (Parameter="productService", ContractName="MyApp.Core.Services.IProductService")' has been set.]
System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePart.EnsureGettable() +422
System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePart.GetExportedValue(ExportDefinition definition) +208
System.ComponentModel.Composition.Hosting.CompositionServices.GetExportedValueFromComposedPart(ImportEngine engine, ComposablePart part, ExportDefinition definition) +131
System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportedValue(ComposablePart part, ExportDefinition export, Boolean isSharedPart) +102
System.ComponentModel.Composition.Hosting.CatalogExport.GetExportedValueCore() +148
System.ComponentModel.Composition.Primitives.Export.get_Value() +76
System.ComponentModel.Composition.ReflectionModel.ImportingItem.Cast(Type type, Export export) +63
System.ComponentModel.Composition.ReflectionModel.ImportingItem.CastSingleExportToImportType(Type type, Export export) +149
System.ComponentModel.Composition.ReflectionModel.ImportingItem.CastExportsToSingleImportType(Export[] exports) +163
System.ComponentModel.Composition.ReflectionModel.ImportingItem.CastExportsToImportType(Export[] exports) +118
System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePart.SetImport(ImportingItem item, Export[] exports) +74
System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePart.SetImport(ImportDefinition definition, IEnumerable`1 exports) +230
System.ComponentModel.Composition.Hosting.PartManager.TrySetImport(ImportDefinition import, IEnumerable`1 exports) +91
System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportSubset(PartManager partManager, IEnumerable`1 imports, AtomicComposition atomicComposition) +449
System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportsStateMachine(PartManager partManager, ComposablePart part) +571
System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImports(PartManager partManager, ComposablePart part, Boolean shouldTrackImports) +277
System.ComponentModel.Composition.Hosting.ImportEngine.SatisfyImports(ComposablePart part) +201
System.ComponentModel.Composition.Hosting.CompositionServices.GetExportedValueFromComposedPart(ImportEngine engine, ComposablePart part, ExportDefinition definition) +77
System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportedValue(ComposablePart part, ExportDefinition export, Boolean isSharedPart) +102
System.ComponentModel.Composition.Hosting.CatalogExport.GetExportedValueCore() +148
System.ComponentModel.Composition.Primitives.Export.get_Value() +76
System.ComponentModel.Composition.ExportServices.GetCastedExportedValue(Export export) +54
System.ComponentModel.Composition.<>c__DisplayClass10`2.<CreateSemiStronglyTypedLazy>b__d() +107
System.Lazy`1.get_Value() +136
MefContrib.Integration.Unity.Strategies.CompositionStrategy.PreBuildUp(IBuilderContext context) +361
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:110
Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp(NamedTypeBuildKey newBuildKey) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\BuilderContext.cs:215
Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilderCustomization\NamedTypeDependencyResolverPolicy.cs:51
BuildUp_MyApp.Core.Services.ClientService(IBuilderContext) +591
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\DynamicMethodBuildPlan.cs:37
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\BuildPlanStrategy.cs:43
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:110
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:511
[ResolutionFailedException: Resolution of the dependency failed, type = "MyApp.Core.Services.ClientService", name = "IFClientService".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - GetExportedValue cannot be called before prerequisite import 'MyApp.Core.Services.RuleService..ctor (Parameter="productService", ContractName="MyApp.Core.Services.IProductService")' has been set.
-----------------------------------------------
At the time of the exception, the container was:
Resolving MyApp.Core.Services.ClientService,IFClientService
Resolving parameter "companyClientValidator" of constructor MyApp.Core.Services.ClientService(MyApp.Core.Repository.IClientRepository repository, MyApp.Core.Validators.IClientValidator validator, MyApp.Core.Validators.IChildClientValidator childClientValidator, MyApp.Core.Services.IReferenceService referenceService, MyApp.Core.Services.IProductService productService, MyApp.Core.Services.IOccupationService occupationService, MyApp.Core.Services.IAdviserService adviserService, MyApp.Core.Validators.ICompanyClientValidator companyClientValidator, MyApp.Core.Repository.IAddressRepository addressRepository)
Resolving MyApp.Core.Validators.ICompanyClientValidator,(none)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: GetExportedValue cannot be called before prerequisite import 'MyApp.Core.Services.RuleService..ctor (Parameter="productService", ContractName="MyApp.Core.Services.IProductService")' has been set.