Are you running IIS in Classic Mode? If so then the standard way of performing a one time initialization at application startup is to use the Application_Start method of Global.asax. See ASP.NET Application Life Cycle Overview for IIS 5.0 and 6.0 for more information.
If you aren't running in Classic Mode, then you would need to perform a one time initialization to load the configuration before using any of the EntLib objects/methods. One way to do this would be to create a common base class that extends WebService and have that base class perform the initialization in a static (shared) constructor. So your code would look something like this:
Finally, since you mention .NET 4.6.1, you could use some sort startup class such as owin startup or webactivatorex.
If you aren't running in Classic Mode, then you would need to perform a one time initialization to load the configuration before using any of the EntLib objects/methods. One way to do this would be to create a common base class that extends WebService and have that base class perform the initialization in a static (shared) constructor. So your code would look something like this:
<WebService(Namespace:="MyWebService")> <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> PublicClass MyWebServiceInterface Inherits MyWebService EndClass
PublicClass MyWebService Inherits System.Web.Services.WebService SharedSubNew() Try' ELib 6.0Dim config As IConfigurationSource = ConfigurationSourceFactory.Create() Dim factory As ExceptionPolicyFactory = New ExceptionPolicyFactory(config) Dim logFactory As LogWriterFactory = New LogWriterFactory(config) Dim dbfactory As DatabaseProviderFactory = New DatabaseProviderFactory() Logger.SetLogWriter(logFactory.Create(), True) Dim exMgr As ExceptionManager = factory.CreateManager() ExceptionPolicy.SetExceptionManager(exMgr, True) Catch ex As Exception ' Simply Ignore' We cannot log or handle Exceptions until LogWriter and ExceptionPolicy is set up...!EndTryTry DatabaseFactory.SetDatabaseProviderFactory(New DatabaseProviderFactory(), True) Catch ex As Exception 'Log exceptions. ExceptionPolicy.HandleException(ex, "Log Only Policy") EndTryEndSubEndClass
Also - do I need to add any Finalize logic for these?No, you don't have to manage the lifetime of the EntLib objects.