title: Substituting Static Methods for Spec
body: <p>I'm trying to use the <a href="https://github.com/Fody/Ionad" rel="nofollow noreferrer">Ionad plugin for Fody</a>. I've created my substitution but the dependent code doesn't call the substitute.</p>
  
  <h3>Substitute</h3>
  
  <pre><code>[StaticReplacement(typeof(AppUtils))]
  public static class AppUtilsSubsitute
  {
      public static void LogException(string func, Exception ex) =&gt; Write("Exception", ex.ToJson());
  
      public static void LogError(string err) =&gt; Write("Error", err);
  
      public static void LogInfo(string info) =&gt; Write("Info", info);
  
      public static void LogWarning(string info) =&gt; Write("Warning", info);
  
      public static void LogCypherQuery(string func, ICypherFluentQuery query) =&gt; Write(func, query.ToJson());
  
      static void Write(string logType, string message)
      {
          var dictionary = new Dictionary&lt;string, string&gt; { { logType, message } };
          var assembly = Assembly.GetExecutingAssembly();
          using (var writer = new StreamWriter(assembly.Location + "Machine.Specifications.log"))
          {
              writer.Write(dictionary.ToJson());
          }
      }
  
      public static Dictionary&lt;string, string&gt; Log()
      {
          var assembly = Assembly.GetExecutingAssembly();
          Dictionary&lt;string, string&gt; content;
          using (var reader = new StreamReader(assembly.GetManifestResourceStream("Machine.Specifications.log")))
          {
              content = JsonConvert.DeserializeObject&lt;Dictionary&lt;string, string&gt;&gt;(reader.ReadToEnd());
          }
          return content;
      }
  }
  </code></pre>
  
  <h3>Dependent Method</h3>
  
  <pre><code>[AttributeUsage(AttributeTargets.Method)]
  public class EnsurePresencesOfAttribute : ActionFilterAttribute
  {
      internal virtual string Required { get; }
      internal virtual string Param { get; }
      public EnsurePresencesOfAttribute(string required = "", string param="request")
      {
          Required = required;
          Param = param;
      }
  
      public override void OnActionExecuting(HttpActionContext actionContext)
      {
          Dictionary&lt;string, object&gt; model = actionContext.ActionArguments;
          if (model == null || model.Count == 0 || !model.ContainsKey(Param))
          {
              ValueError(actionContext, $"{Param} parameter");
              return;
          }
          foreach (var requirement in Required.Split(',').Select(e =&gt; e.Trim()))
          {
              if (model[requirement] == null)
              {
                  ValueError(actionContext, requirement);
                  return;
              }
          }
          base.OnActionExecuting(actionContext);
      }
  
      public override Task OnActionExecutingAsync(HttpActionContext context, CancellationToken token)
      {
          Dictionary&lt;string, object&gt; model = context.ActionArguments;
          if(model == null || model.Count == 0 || !model.ContainsKey(Param))
          {
              ValueError(context, $"{Param} parameter");
              return Task.FromResult(0);
          }
          foreach (var requirement in Required.Split(',').Select(e =&gt; e.Trim()))
          {
              if (model[requirement] == null)
              {
                  ValueError(context, requirement);
                  Task.FromResult(0);
              }
          }
          return base.OnActionExecutingAsync(context, token);
      }
  
      private static void ValueError(HttpActionContext context, string requirement)
      {
          var action = context.ActionDescriptor.ActionName;
          AppUtils.LogError($"{action} Failed : Missing Required Attribute {requirement}. ");
          using (var controller = new BaseApiController { Request = new HttpRequestMessage() })
          {
              controller.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());
              context.Response = controller.InvalidInputResponse();
          }
      }
  }
  </code></pre>