title: What is alternate of ServiceBus MessagingFactory in .Net Core?
body: <p>While converting my project from .Net framework 4.7 to .Net core 2.1, I'm facing issue with Servicebus <code>MessagingFactory</code>. I don't see any <code>MessagingFactory</code> class in new nuget package <code>Microsoft.Azure.ServiceBus</code> for .Net core.</p>
  
  <p><strong>My .Net framework 4.7 Code</strong></p>
  
  <pre><code>private static readonly string messagingConnectionString = Environment.GetEnvironmentVariable("ServiceBusConnection");
  
      private static Lazy&lt;MessagingFactory&gt; lazyMessagingFactory = new Lazy&lt;MessagingFactory&gt;(() =&gt;
      {
          return MessagingFactory.CreateFromConnectionString(messagingConnectionString);
      });
  
      public static MessagingFactory MessagingFactory
      {
          get
          {
              return lazyMessagingFactory.Value;
          }
      }
  
  public static MessagingFactory EventHubMessageFactory
      {
          get
          {
              return lazyEventhubMessagingFactory.Value;
          }
      }
  
  public async Task SendMessageToQueueAsync(string queueName, string message)
      {
          QueueClient queueClient = MessagingFactory.CreateQueueClient(queueName);
          BrokeredMessage brokeredMessage = new BrokeredMessage(new MemoryStream(Encoding.UTF8.GetBytes(message)), true);
          await queueClient.SendAsync(brokeredMessage);
      }
  </code></pre>
  
  <p>It was a <a href="https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-performance-improvements#reusing-factories-and-clients" rel="nofollow noreferrer">best practices</a> for high performance application, Also I have many queues under single service bus namespace and I push message based on configuration. I don't want to create <code>QueueClient</code> object in every request and don't want to maintain connection string for every queue.</p>
  
  <p>What is alternate of <code>MessagingFactory</code> in .Net Core?</p>