/// <summary> /// Returns a correct implementation of the persistence provider according to environment variables. /// </summary> /// <remarks>If the environment invariants have failed to hold upon creation of the storage provider, /// a <em>null</em> value will be provided.</remarks> public async Task <IStorageProvider> GetStorageProvider(string storageInvariant) { //Make sure the environment invariants hold before trying to give a functioning SUT instantiation. //This is done instead of the constructor to have more granularity on how the environment should be initialized. try { using (await StorageLock.LockAsync()) { if (AdoNetInvariants.Invariants.Contains(storageInvariant)) { if (!StorageProviders.ContainsKey(storageInvariant)) { Storage = Invariants.EnsureStorageForTesting(Invariants.ActiveSettings.ConnectionStrings.First(i => i.StorageInvariant == storageInvariant)); var properties = new Dictionary <string, string>(); properties["DataConnectionString"] = Storage.Storage.ConnectionString; properties["AdoInvariant"] = storageInvariant; var config = new ProviderConfiguration(properties, null); var storageProvider = new AdoNetStorageProvider(); await storageProvider.Init(storageInvariant + "_StorageProvider", DefaultProviderRuntime, config); StorageProviders[storageInvariant] = storageProvider; } } } } catch { StorageProviders.Add(storageInvariant, null); } return(StorageProviders[storageInvariant]); }
/// <summary> /// Returns a correct implementation of the persistence provider according to environment variables. /// </summary> /// <remarks>If the environment invariants have failed to hold upon creation of the storage provider, /// a <em>null</em> value will be provided.</remarks> public async Task <IGrainStorage> GetStorageProvider(string storageInvariant) { //Make sure the environment invariants hold before trying to give a functioning SUT instantiation. //This is done instead of the constructor to have more granularity on how the environment should be initialized. try { using (await StorageLock.LockAsync()) { if (AdoNetInvariants.Invariants.Contains(storageInvariant)) { if (!StorageProviders.ContainsKey(storageInvariant)) { Storage = Invariants.EnsureStorageForTesting(Invariants.ActiveSettings.ConnectionStrings.First(i => i.StorageInvariant == storageInvariant)); var options = new AdoNetGrainStorageOptions() { ConnectionString = Storage.Storage.ConnectionString, Invariant = storageInvariant }; var clusterOptions = new ClusterOptions() { ServiceId = Guid.NewGuid().ToString() }; var storageProvider = new AdoNetGrainStorage(DefaultProviderRuntime.ServiceProvider.GetService <ILogger <AdoNetGrainStorage> >(), DefaultProviderRuntime, Options.Create(options), Options.Create(clusterOptions), storageInvariant + "_StorageProvider"); ISiloLifecycleSubject siloLifeCycle = new SiloLifecycleSubject(NullLoggerFactory.Instance.CreateLogger <SiloLifecycleSubject>()); storageProvider.Participate(siloLifeCycle); await siloLifeCycle.OnStart(CancellationToken.None); StorageProviders[storageInvariant] = storageProvider; } } } } catch { StorageProviders.Add(storageInvariant, null); } return(StorageProviders[storageInvariant]); }