Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What was changed in the DI container , v1.9.0-preview-18169 #15715

Closed
hyzx86 opened this issue Apr 10, 2024 · 2 comments
Closed

What was changed in the DI container , v1.9.0-preview-18169 #15715

hyzx86 opened this issue Apr 10, 2024 · 2 comments
Labels

Comments

@hyzx86
Copy link
Contributor

hyzx86 commented Apr 10, 2024

Describe the bug

To Reproduce

Steps to reproduce the behavior:

I recently updated to 1.9.0-preview-18169 and found that the original service replacement code did not work and threw the following exception,
This service descriptor is keyed. Your service provider may not support keyed services

But it worked fine in previous versions. Have we made any recent changes to the container? What is the recommended practice?

The following code is just one example, and I've actually replaced many implementations :

           var ocLuceneIndexingHandler =
               services.FirstOrDefault(x =>   x.ImplementationType == typeof(LuceneIndexingContentHandler));
    if (ocLuceneIndexingHandler != null)
    {
        services.Remove(ocLuceneIndexingHandler);
        services.AddScoped<IContentHandler, EocLuceneIndexingContentHandler>();
    }

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots


 EasyOC.Scripting.Queries.Tests.ScriptQueryServiceTests.DynamicIndexTest
  源: ScriptQueryServiceTests.cs 行 237
  持续时间: 12.4 秒

 消息: 
System.InvalidOperationException : This service descriptor is keyed. Your service provider may not support keyed services.

 堆栈跟踪: 
ServiceDescriptor.ThrowKeyedDescriptor()
ServiceDescriptor.get_ImplementationType()
<>c.<ConfigureServices>b__0_0(ServiceDescriptor x) 行 19
Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
Startup.ConfigureServices(IServiceCollection services) 行 18
ShellContainerFactory.CreateContainerAsync(ShellSettings settings, ShellBlueprint blueprint)
ShellContextFactory.CreateDescribedContextAsync(ShellSettings settings, ShellDescriptor shellDescriptor)
IShellContextFactory.CreateShellContextAsync(ShellSettings settings)
ShellHost.GetOrCreateShellContextAsync(ShellSettings settings)
<另外 37 个帧…>
ShellScope.UsingAsync(Func`2 execute, Boolean activateShell)
ModularTenantContainerMiddleware.Invoke(HttpContext httpContext)
<<SendAsync>g__RunRequestAsync|0>d.MoveNext()
--- End of stack trace from previous location ---
ClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
SiteContext.InitializeAsync(String recipeName) 行 104
ScriptQueryContext.InitializeAsync() 行 15
ScriptQueryServiceTests.DynamicIndexTest() 行 240
--- End of stack trace from previous location ---

 (结果具有附加输出) 

  打开测试日志

@hyzx86 hyzx86 changed the title What was changed in the DI container What was changed in the DI container , v1.9.0-preview-18169 Apr 10, 2024
@hyzx86
Copy link
Contributor Author

hyzx86 commented Apr 10, 2024

Hi @MikeAlhayek , is this issue related to this PR #14998 ?

@hyzx86
Copy link
Contributor Author

hyzx86 commented Apr 10, 2024

resolved ,just add a condition !x.IsKeyedService

     var ocLuceneIndexingHandler =
               services.FirstOrDefault(x => !x.IsKeyedService&&   x.ImplementationType == typeof(LuceneIndexingContentHandler));
    if (ocLuceneIndexingHandler != null)
    {
        services.Remove(ocLuceneIndexingHandler);
        services.AddScoped<IContentHandler, EocLuceneIndexingContentHandler>();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant