OCPPWSServerFactory.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using EVCB_OCPP.WSServer.Service;
  2. using Microsoft.Extensions.Configuration;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using Microsoft.Extensions.Logging;
  5. using OCPPServer.Protocol;
  6. using SuperWebSocket.SubProtocol;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace OCPPServer.Protocol;
  13. public interface IOCPPWSServerFactory
  14. {
  15. OCPPWSServer Create(IEnumerable<ISubProtocol<ClientData>> subProtocols);
  16. }
  17. public class OCPPWSServerFactory : IOCPPWSServerFactory
  18. {
  19. public OCPPWSServerFactory(
  20. IConfiguration configuration,
  21. IMainDbService mainDbService,
  22. ILoggerFactory loggerFactory,
  23. IServiceProvider serviceProvider)
  24. {
  25. this.loggerFactory = loggerFactory;
  26. this.serviceProvider = serviceProvider;
  27. }
  28. public OCPPWSServer Create(IEnumerable<ISubProtocol<ClientData>> subProtocols)
  29. {
  30. var logger = loggerFactory.CreateLogger<OCPPWSServer>();
  31. var server = serviceProvider.GetRequiredService<OCPPWSServer>();
  32. server.RegisterSubProtocol(subProtocols);
  33. return server;
  34. }
  35. private readonly ILoggerFactory loggerFactory;
  36. private readonly IServiceProvider serviceProvider;
  37. }