BotBuilder-Samples: IStatePropertyAccessor can not be injected through DI in 45.state-management sample
Sample information
- Sample type: State Management
- Sample language: dotnetcore
- Sample name: 45.state-management
Describe the bug
The Conversation State and User State are creating property inside bot and using the value. In case same property needs to be updated for a separate dialog, then will it require Creating the Property Again. Dont seem to find a way to achieve this using DI.
To Reproduce
Steps to reproduce the behavior:
- Try to add a dialog and access the PromptedUserForName property inside it without using CreateProperty method
- Try to add IStatePropertyAccessor through DI and it fails -
System.ArgumentException
HResult=0x80070057
Message=Cannot instantiate implementation type 'Microsoft.Bot.Builder.IStatePropertyAccessor`1[ChatBot.Classic.App.Models.ConversationStateDataModel]' for service type 'Microsoft.Bot.Builder.IStatePropertyAccessor`1[ChatBot.Classic.App.Models.ConversationStateDataModel]'.
Source=Microsoft.Extensions.DependencyInjection
StackTrace:
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.Populate(IEnumerable`1 descriptors)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory..ctor(IEnumerable`1 descriptors)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine..ctor(IEnumerable`1 serviceDescriptors, IServiceProviderEngineCallback callback)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CompiledServiceProviderEngine..ctor(IEnumerable`1 serviceDescriptors, IServiceProviderEngineCallback callback)
at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(IEnumerable`1 serviceDescriptors, ServiceProviderOptions options)
at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options)
at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.Initialize()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at ChatBot.Classic.App.Program.Main(String[] args) in C:\Projects\TPGit\ChatBot\src\ChatBot.Classic.App\Program.cs:line 10
Expected behavior
DI should allow injecting the IStatePropertyAccessor and the same Conversation Property should be accessed and updated from different dialogs.
Screenshots
None
Additional context
Update the sample to include the context of multiple dialogs accessing the state and updating.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (10 by maintainers)
@mutanttech I played around with this some more and you actually can use DI. Basic steps:
I think some of our older samples used this method, as well. I’m not sure if this is the best method or not. @johnataylor: If you could chime in on this, that would be great.
@sgellock @johnataylor
I don’t see that we have a current sample that shows how to address this. Would it be worth writing one up? I’m not sure if there’s a better way than my suggestion that uses the newer changes to the SDK like using DI for dialogs and using the DialogExtensions
…or am I just missing something? Like @mutanttech, I tried to use DI but encountered the same error.
@mdrichardson, please attempt a repro and if found investigate an update for the sample to include the context of multiple dialogs accessing the state and updating.