/// <summary> /// Register the bot framework with Asp.net. /// </summary> /// <param name="config">Represents the configuration of the HttpServer.</param> public static void Register(HttpConfiguration config) { config.MapBotFramework(botConfig => { // Load Connected Services from .bot file var path = HostingEnvironment.MapPath(@"~/EchoBot.bot"); var botConfigurationFile = BotConfiguration.Load(path); var endpointService = (EndpointService)botConfigurationFile.Services.First(s => s.Type == "endpoint"); botConfig .UseMicrosoftApplicationIdentity(endpointService?.AppId, endpointService?.AppPassword); // The Memory Storage used here is for local bot debugging only. When the bot // is restarted, everything stored in memory will be gone. IStorage dataStore = new MemoryStorage(); // Create Conversation State object. // The Conversation State object is where we persist anything at the conversation-scope. var conversationState = new ConversationState(dataStore); botConfig.BotFrameworkOptions.State.Add(conversationState); // Create the custom state accessor. // State accessors enable other components to read and write individual properties of state. var accessors = new EchoBotAccessors(conversationState) { CounterState = conversationState.CreateProperty <CounterState>(EchoBotAccessors.CounterStateName), }; UnityConfig.Container.RegisterInstance <EchoBotAccessors>(accessors, new ContainerControlledLifetimeManager()); }); }
/// <summary> /// Initializes a new instance of the <see cref="EchoWithCounterBot"/> class. /// </summary> /// <param name="accessors">A class containing <see cref="IStatePropertyAccessor{T}"/> used to manage state.</param> public EchoWithCounterBot(EchoBotAccessors accessors) { _accessors = accessors ?? throw new System.ArgumentNullException(nameof(accessors)); }