title: How to access storage without dependency injection on every dialog in botframework V4
body: <p>Hello i am trying to migrate my code from the Bot Framework v4 design last January to the new design now. In the previous code i can just call this code:</p>
  
  <pre><code>var userstate = await (stepContext.Context.TurnState["BasicAccessors"] as BasicAccessors).BasicUserStateAccessor.GetAsync(stepContext.Context);
  </code></pre>
  
  <p>on every dialog to access the storage but not i can't do it and i need to to dependency injection everytime. How to implement this code on this new design? Thank you.</p>
  
  <pre><code>    namespace BasicBot
      {
      public class BasicAccessors
      {
          public BasicAccessors(ConversationState conversationState, UserState userState)
          {
              ConversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
              UserState = userState ?? throw new ArgumentException(nameof(userState));
          }
  
          public static string DialogStateAccessorName { get; } = $"{nameof(BasicAccessors)}.DialogState";
  
          public static string BasicUserStateAccessorName { get; } = $"{nameof(BasicAccessors)}.BasicUserState";
  
          public IStatePropertyAccessor&lt;BasicUserState&gt; BasicUserStateAccessor { get; internal set; }
  
          public IStatePropertyAccessor&lt;DialogState&gt; DialogStateAccessor { get; internal set; }
  
          public ConversationState ConversationState { get; }
  
          public UserState UserState { get; }
      }
  }
  </code></pre>
  
  <p>bot code:</p>
  
  <pre><code> public class DialogBot&lt;T&gt; : ActivityHandler where T : Dialog
  {
      protected readonly Dialog Dialog;
      protected readonly BotState ConversationState;
      protected readonly BotState UserState;
      protected readonly ILogger Logger;
  
      public DialogBot(ConversationState conversationState, UserState userState, T dialog, ILogger&lt;DialogBot&lt;T&gt;&gt; logger)
      {
          ConversationState = conversationState;
          UserState = userState;
          Dialog = dialog;
          Logger = logger;
      }
  
      public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
      {
          await base.OnTurnAsync(turnContext, cancellationToken);
  
          // Save any state changes that might have occured during the turn.
          var userStateAccessors = UserState.CreateProperty&lt;BookingDetails&gt;(nameof(BookingDetails));
          await ConversationState.SaveChangesAsync(turnContext, false, cancellationToken);
          await UserState.SaveChangesAsync(turnContext, false, cancellationToken);
      }
  
      protected override async Task OnMessageActivityAsync(ITurnContext&lt;IMessageActivity&gt; turnContext, CancellationToken cancellationToken)
      {
          Logger.LogInformation("Running dialog with Message Activity.");
  
          // Run the Dialog with the new message Activity.
          await Dialog.Run(turnContext, ConversationState.CreateProperty&lt;DialogState&gt;("DialogState"), cancellationToken);
      }
  }
  </code></pre>
  
  <p>startup:</p>
  
  <pre><code>  public class Startup
  {
      public Startup()
      {
      }
  
      // This method gets called by the runtime. Use this method to add services to the container.
      public void ConfigureServices(IServiceCollection services)
      {
          services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  
          // Create the credential provider to be used with the Bot Framework Adapter.
          services.AddSingleton&lt;ICredentialProvider, ConfigurationCredentialProvider&gt;();
  
          // Create the Bot Framework Adapter with error handling enabled.
          services.AddSingleton&lt;IBotFrameworkHttpAdapter, AdapterWithErrorHandler&gt;();
  
          // Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.)
          services.AddSingleton&lt;IStorage, MemoryStorage&gt;();
  
          // Create the User state. (Used in this bot's Dialog implementation.)
          services.AddSingleton&lt;UserState&gt;();
  
          // Create the Conversation state. (Used by the Dialog system itself.)
          services.AddSingleton&lt;ConversationState&gt;();
  
          services.AddSingleton&lt;BasicAccessors&gt;();
  
          // The Dialog that will be run by the bot.
          services.AddSingleton&lt;MainDialog&gt;();
  
          // Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
          services.AddTransient&lt;IBot, DialogBot&lt;MainDialog&gt;&gt;();
  
  
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IHostingEnvironment env)
      {
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
          else
          {
              app.UseHsts();
          }
  
          app.UseDefaultFiles();
          app.UseStaticFiles();
  
          //app.UseHttpsRedirection();
          app.UseMvc();
      }
  }
  </code></pre>
  
  <p>}</p>