HypervHost GetHost(string hostName) { if (string.IsNullOrEmpty(hostName)) { throw new ArgumentNullException(nameof(hostName)); } hostName = hostName.ToLower(); if (!_hosts.TryGetValue(hostName, out var host)) { var options = new HyperVHostOptions { HostName = hostName, UserName = _options.UserName, KeyFile = _options.KeyFile, DefaultStorage = _options.DefaultStorage }; host = ActivatorUtilities.CreateInstance <HypervHost>(_scope.ServiceProvider, Options.Create(options)); ImmutableDictionary <string, HypervHost> current; ImmutableDictionary <string, HypervHost> result; do { current = _hosts; result = current.SetItem(hostName, host); }while (Interlocked.Exchange(ref _hosts, result) != current); } return(host); }
public async Task <IHypervHost> GetHypervHostAsync(string hostName) { if (_host is null) { //todo read config Token=Configuration["somesection:somekey"] var options = new HyperVHostOptions { HostName = hostName, UserName = "******" }; _host = new HypervHost(Options.Create(options), null); //await services.ConnectAsync(); } return(_host); }