title: c# defer the save implementation
body: <p>I need assists ;-) to be honest not sure what to call it so if people come up with the more correct wording I will change the title to suit.</p>
  
  <p>I have written a class for 'what ever' the class is like a utility class.. can be used in many projects across the entire app.</p>
  
  <p>In the utility class.. there is a reference to the EF DB Context. This is for when i want to persist the results into the database.</p>
  
  <p>I would like to remove the dependency on this being in the Utility class and rather pass in the save method.</p>
  
  <p>I am struggling to figure out how you would do this. i.e. with c# Action i know you can pass in a method to be preformed i.e a pointer to a function. But how do I let that pointer know about things inside my Utility case.</p>
  
  <p>I hope i worded all that correctly, please assist with either an example or link to what i am on about.</p>
  
  <p>Showing code: not sure its necessary in this case. But here is a crude example.</p>
  
  <pre><code>public class UtilityCase
  {
      public List&lt;Person&gt; Persons = new List&lt;Person&gt;();
  
      public void AddPerson(string name)
      {
  
          Person newPerson = new Person {Name = name};
          Persons.Add(newPerson);
  
          if (Persons.Count &gt; 10)
          {
              PersistClear();
          }
  
      }
  
      public void PersistClear()
      {
          //I want to be able to Set this from outside of the UtilityCase
          var context = new Context();
  
          //I want to remove the referance to the Entity (DB) Person
          foreach (Person item in Persons)
          {
              //add person to db 
          }
          context.saveChanges();
  
          Persons.Clear();
      }
  
  }
  </code></pre>
  
  <p>DB entity case  </p>
  
  <pre><code>public class Person
  {
     public string Name { get; set; }
  }
  </code></pre>
  
  <p>So I understand that i would need to create a local class to the Utility to remove the reference to the Person (DB) but how do i get my function to inject to know about things inside the UtilityCase. Thanks</p>