/src/LinFu.AOP.Interfaces/ExceptionHandlerRegistry.cs
http://github.com/philiplaureano/LinFu · C# · 42 lines · 23 code · 4 blank · 15 comment · 3 complexity · 0c8e382a29d347ca66424d2f0b84c09a MD5 · raw file
- namespace LinFu.AOP.Interfaces
- {
- /// <summary>
- /// Represents a class that stores <see cref="IExceptionHandler" /> instances in a central location.
- /// </summary>
- public static class ExceptionHandlerRegistry
- {
- private static IExceptionHandler _handler;
- private static readonly object _lock = new object();
- /// <summary>
- /// Gets the <see cref="IExceptionHandler" /> instance that can handle the current exception.
- /// </summary>
- /// <param name="info">
- /// The <see cref="IExceptionHandlerInfo" /> instance that describes the context of the thrown
- /// exception.
- /// </param>
- /// <returns>An exception handler.</returns>
- public static IExceptionHandler GetHandler(IExceptionHandlerInfo info)
- {
- if (_handler == null)
- return null;
- if (!_handler.CanCatch(info))
- return null;
- return _handler;
- }
- /// <summary>
- /// Sets the <see cref="IExceptionHandler" /> instance that can handle all thrown exceptions.
- /// </summary>
- /// <param name="handler">The exception handler.</param>
- public static void SetHandler(IExceptionHandler handler)
- {
- lock (_lock)
- {
- _handler = handler;
- }
- }
- }
- }