-
Notifications
You must be signed in to change notification settings - Fork 307
/
Copy pathVbeProvider.cs
39 lines (36 loc) · 1.55 KB
/
VbeProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using Rubberduck.Runtime;
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
using Rubberduck.VBEditor.VbeRuntime;
namespace Rubberduck
{
/// <summary>
/// ANTI-PATTERN: Service locator for COM class. Think carefully before using it, and regret it.
/// </summary>
/// <remarks>
/// This is a hacky workaround to provide support to COM-visible classes without breaking the
/// interface or violating the security settings of the Office host. Because a COM class must
/// have a parameterless constructor if it is to be newed up and because COM class cannot come
/// from the IoC container nor have any dependencies coming out of it, we use the service
/// locator anti-pattern here to provide the necessary functionality for the COM classes'
/// internal implementations. The use should never expand beyond that limited scope.
/// </remarks>
internal static class VbeProvider
{
internal static void Initialize(IVBE vbe, IVbeNativeApi vbeNativeApi, IBeepInterceptor beepInterceptor)
{
Vbe = vbe;
VbeNativeApi = vbeNativeApi;
BeepInterceptor = beepInterceptor;
}
internal static void Terminate()
{
Vbe = null;
VbeNativeApi = null;
BeepInterceptor?.Dispose();
BeepInterceptor = null;
}
internal static IVBE Vbe { get; private set; }
internal static IVbeNativeApi VbeNativeApi { get; private set; }
internal static IBeepInterceptor BeepInterceptor { get; private set; }
}
}