Scenario:
Logger with Lazy loadingSolution:
- Loading Logger when needed
using System.Collections; namespace Web.Models { public static class Class { private static readonly Lazy<Logger> Logger; public static Class() { Logger = new Lazy<Logger>(() => Get<ILoggerFactory>().GetLogger())); } public bool Validate() { Logger.Value.Error(e, $"Error") } } }
No comments:
Post a Comment