C# 从DelegateCommand继承而不使用静态属性

C# 从DelegateCommand继承而不使用静态属性,c#,wpf,unity-container,C#,Wpf,Unity Container,如何在这段代码中避免静态属性: public class RoleCommand : RoleBaseCommand, IRoleCommand { #region Properties public static IUnityContainer Container { get; set; } public static IMitarbeiterRepository Repository { get; set; } public static IInformati

如何在这段代码中避免静态属性:

public class RoleCommand : RoleBaseCommand, IRoleCommand
{
    #region Properties
    public static IUnityContainer Container { get; set; }
    public static IMitarbeiterRepository Repository { get; set; }
    public static IInformation Information { get; set; }


    #endregion

    #region Methods
    public RoleCommand(Action executeMethod, Func<bool> canExecuteMethod = null, string roleName = null,
        IUnityContainer container = null)
        : base(executeMethod, () => canExecuteMethod == null ? HasRecht() : HasRecht() && canExecuteMethod(), roleName)
    {
        if (executeMethod == null)
            throw new ArgumentNullException("executeMethod");

        if (!string.IsNullOrWhiteSpace(roleName) && container == null)
            throw new InvalidOperationException(
                "Der UnityContainer darf nicht null sein wenn der RoleName gefüllt ist.");

        if (string.IsNullOrWhiteSpace(roleName) && container != null)
            throw new InvalidOperationException(
                "Der RoleName darf nicht null sein wenn der IUnityContainer nicht null ist.");


        if (!string.IsNullOrWhiteSpace(roleName) && container != null)
        {
            Container = container;
            Repository = container.Resolve<IMitarbeiterRepository>();
            Information = container.Resolve<IInformation>();
        }
    }

    /// <summary>
    /// Gibt an ob der Mitarbeiter das Recht hat diese Aktion auszuführen.
    /// </summary>
    protected static bool HasRecht()
    {
        return Repository.HasMitarbeiterARoleWith(RoleName, Information.CurrentMitarbeiter);
    }
    #endregion
}
公共类角色命令:RoleBaseCommand、IRoleCommand
{
#区域属性
公共静态IUnityContainer容器{get;set;}
公共静态IMitarbeiterRepository存储库{get;set;}
公共静态信息信息{get;set;}
#端区
#区域方法
公共角色命令(Action executeMethod,Func canExecuteMethod=null,string roleName=null,
IUnityContainer容器=空)
:base(executeMethod,()=>canExecuteMethod==null?HasRecht():HasRecht()&canExecuteMethod(),roleName)
{
if(executeMethod==null)
抛出新ArgumentNullException(“executeMethod”);
如果(!string.IsNullOrWhiteSpace(roleName)&&container==null)
抛出新的InvalidOperationException(
“在全球环境基金中,单位容器不存在任何无效内容。”);
if(string.IsNullOrWhiteSpace(roleName)&&container!=null)
抛出新的InvalidOperationException(
“不包含任何内容的角色不包含任何内容。”);
如果(!string.IsNullOrWhiteSpace(roleName)&&container!=null)
{
容器=容器;
Repository=container.Resolve();
Information=container.Resolve();
}
}
/// 
///这是一个很好的选择。
/// 
受保护的静态bool HasRecht()
{
返回Repository.hasmitarbeiterrolewith(RoleName,Information.CurrentMitarbeiter);
}
#端区
}
RoleBaseCommand类继承自WPF的Unity/Prism框架的DelegateCommand。我还使用依赖注入


只有当HasRecht()方法返回true时,我才想执行该命令。

您想做什么并不清楚。我试着把几个例子放在一起,但是在不知道你想要什么的情况下,我还是做不到。提供如何实例化
RoleCommand
的示例,以及何时使用
HasRecht
的示例,以便我们更好地了解您需要执行的操作。实例化:
new RoleCommand(SaveChangesExecuteMethod,roleName:“EditMitarbeiter”,container:container)
如果某人有权执行命令,HasRecht方法将返回bool。