From addf0cdd4a0ff3cffed68aa3df9166625046658c Mon Sep 17 00:00:00 2001 From: ROBERTO ALVES PEREIRA Date: Fri, 1 Mar 2024 12:46:33 -0300 Subject: [PATCH] fix: criar uma instancia para cada instancia do SoapUtils , nunca utilizar a mesma --- DFe.Wsdl/Common/ConfiguracaoServicoWSDL.cs | 18 +++++++++++++++--- DFe.Wsdl/Common/SoapUtils.cs | 13 ++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/DFe.Wsdl/Common/ConfiguracaoServicoWSDL.cs b/DFe.Wsdl/Common/ConfiguracaoServicoWSDL.cs index 32464bcfd..5b192c3ea 100644 --- a/DFe.Wsdl/Common/ConfiguracaoServicoWSDL.cs +++ b/DFe.Wsdl/Common/ConfiguracaoServicoWSDL.cs @@ -1,14 +1,26 @@ -namespace DFe.Wsdl.Common +using System; + +namespace DFe.Wsdl.Common { public static class ConfiguracaoServicoWSDL { public static bool ValidarCertificadoDoServidorNetCore { get; set; } - public static IRequestSefaz RequestSefaz { get; set; } + private static Func _requestSefazFactory; + + public static void SetRequestSefazFactory(Func factory) + { + _requestSefazFactory = factory; + } + + public static IRequestSefaz GetRequestSefaz() + { + return _requestSefazFactory(); + } static ConfiguracaoServicoWSDL() { ValidarCertificadoDoServidorNetCore = true; - RequestSefaz = new RequestSefazDefault(); + SetRequestSefazFactory(() => new RequestSefazDefault()); } } } \ No newline at end of file diff --git a/DFe.Wsdl/Common/SoapUtils.cs b/DFe.Wsdl/Common/SoapUtils.cs index 2e986ce66..53e4360cd 100644 --- a/DFe.Wsdl/Common/SoapUtils.cs +++ b/DFe.Wsdl/Common/SoapUtils.cs @@ -18,6 +18,13 @@ namespace CTe.CTeOSDocumento.Soap /// public class SoapUtils { + private IRequestSefaz _requestSefaz; + + public SoapUtils() + { + _requestSefaz = ConfiguracaoServicoWSDL.GetRequestSefaz(); + } + /// /// Serializa a estrutura do envelope contida no objeto para um XmlDocument. /// @@ -26,7 +33,7 @@ public class SoapUtils /// public XmlDocument SerealizeDocument(T soapEnvelope) { - return ConfiguracaoServicoWSDL.RequestSefaz.SerealizeDocument(soapEnvelope); + return _requestSefaz.SerealizeDocument(soapEnvelope); } /// @@ -40,12 +47,12 @@ public XmlDocument SerealizeDocument(T soapEnvelope) /// public async Task SendRequestAsync(XmlDocument xmlEnvelop, X509Certificate2 certificadoDigital, string url, int timeOut, TipoEvento? tipoEvento = null, string actionUrn = "") { - return await ConfiguracaoServicoWSDL.RequestSefaz.SendRequestAsync(xmlEnvelop, certificadoDigital, url, timeOut, tipoEvento, actionUrn); + return await _requestSefaz.SendRequestAsync(xmlEnvelop, certificadoDigital, url, timeOut, tipoEvento, actionUrn); } public string SendRequest(XmlDocument xmlEnvelop, X509Certificate2 certificadoDigital, string url, int timeOut, TipoEvento? tipoEvento = null, string actionUrn = "") { - return ConfiguracaoServicoWSDL.RequestSefaz.SendRequest(xmlEnvelop, certificadoDigital, url, timeOut, tipoEvento, actionUrn); + return _requestSefaz.SendRequest(xmlEnvelop, certificadoDigital, url, timeOut, tipoEvento, actionUrn); } }