Обычно я не защищаю создание синглтонов, но, как упоминалось здесь , они иногда могут быть полезны. Поскольку вы не используете DI, это может быть хорошим вариантом использования.
Например, что если вы сделаете свой класс ConnectToServer
stati c?
public static class Connecting
{
private static ManagementScope scope;
public static void SetScope(Server sv)
{
// WMI scope
ConnectionOptions options = new ConnectionOptions
{
Username = sv.User,
Password = sv.Pass
};
scope = new ManagementScope(@"\\" + sv.Name + @"\root\cimv2", options);
scope.Connect();
}
public static ManagementScope GetScope { get { return scope; } }
}
Тогда в вашем Proceed
действие:
// ---------- This is the function returning the scope ---------- \\
Connecting.SetScope(serverModel);
// ---------- This is the function returning the scope ---------- \\
И в вашем ExportProceed
действии:
// ---------- This is where i need to pass the scope ---------- \\
var scope = Connecting.GetScope;
ExportProcess.CreateDirectories(ex, scope);
// ---------- This is where i need to pass the scope ---------- \\