title: Creational Patterns suggestion
body: <p>I'm struggling to find a good way to handle a problem that seems to be nice.</p>
  
  <p>My entire model relies on the concept of pricing strategies. These strategies  calculate a specific price based on rules. Rules just how to calculate the price for a given time range (8AM to 12AM cost you that amount of money...)</p>
  
  <p>I currently have 6 strategies, each of them inheriting from RuledBasedPricingStrategy which itself implements IStrategy</p>
  
  <pre><code>public abstract class RuledBasedPricingStrategy : IPricingStrategy
  {
      public abstract string FriendlyName { get; }
      protected abstract ICollection&lt;IPricingRule&gt; Rules { get; }
  
      protected Booking Booking { get; }
      protected Resource Resource { get; }
      protected TecTacClient Client { get; }
  
      protected RuledBasedPricingStrategy(Booking booking, Resource resource, TecTacClient client)
      { 
         // Just checking and assigning values(...) 
      }
  
      public abstract bool IsEligible();
  
      public Pricing Build()
      {
          var strategy = new Pricing(FriendlyName, Resource.CurrencyCode);
          foreach (var r in Rules.OrderByDescending(x =&gt; x.Priority))
              r.Apply(strategy, Booking, Resource, Client);
          return strategy;
      }
  }
  
  public class RegularPricingCalculatorFactory : RuledBasedPricingStrategy
  {
      public override string FriendlyName =&gt; "Regular Pricing";
  
      protected override ICollection&lt;IPricingRule&gt; Rules =&gt; new List&lt;IPricingRule&gt;
      {
          new OfficeHourPricingRule(),
          // Non Office Hours
          new OnePercentSurchagePricingRule()
      };
  
      public override bool IsEligible() =&gt; (...)
  
      public RegularPricingCalculatorFactory(Booking booking, Resource resource, TecTacClient client)
          : base(booking, resource, client)
      { }
  }
  
  public class HalfdayPricingStrategy : RuledBasedPricingStrategy
  {
      public override string FriendlyName =&gt; "Half day Pricing";
  
      protected override ICollection&lt;IPricingRule&gt; Rules =&gt; new List&lt;IPricingRule&gt;
      {
          new HalfDayPricingRule(),
          new OfficeHourPricingRule(),
          // Non Office Hours
      };
  
      public override bool IsEligible() =&gt; (...)
  
      public HalfdayPricingStrategy(Booking booking, Resource resource, TecTacClient client) 
          : base(booking, resource, client) { }
  }
  </code></pre>
  
  <p>IRule is a simple interface. Rules accepts a pricing as a parameter and will add as many pricing steps as necessary:</p>
  
  <pre><code>public interface IPricingRule
  {
      int Priority { get; }
      void Apply(Pricing pricing, Booking booking, Resource resource, TecTacClient client);
  }
  </code></pre>
  
  <p>The pricing is a simple class as shown below:</p>
  
  <pre><code>public class Pricing
  {
      public string Name { get; }
      public string CurrencyCode { get; }
      private readonly List&lt;PricingStep&gt; _steps;
      public ICollection&lt;PricingStep&gt; Steps =&gt; _steps.AsReadOnly();
      public decimal TotalPrice =&gt; Steps.Sum(x =&gt; x.Price);
   }
  </code></pre>
  
  <p>And so on (...)</p>
  
  <p>I'm looking for a good way to instantiate all these strategies. As you noticed they take the booking, resource and client objects as ctor arguments. My initial point was to avoid passing these argument twice (IsEligible and Build). However then I need to build a "factory" that will know all strategy types and instantiate them every time I get a new request:</p>
  
  <pre><code>    public IEnumerable&lt;IPricingStrategy&gt; Find(Booking booking, Resource resource, TecTacClient client)
          =&gt; _strategiesType
              .Select(t =&gt; Activator.CreateInstance(t, booking, resource, client))
              .OfType&lt;IPricingStrategy&gt;();
  </code></pre>
  
  <p>It does not seem to be the right approach. Strategy should be instantiated once and then reused to calculate strategy. However I can't in that case I will end up doing something like</p>
  
  <pre><code>foreach(var s in strategies)
      if (s.IsEligible(booking, resource, client))
          yield return s.Build(booking, resource, client);
  </code></pre>
  
  <p>What patterns could I use to simplify/clean this code?</p>
  
  <p>Thx 
  Seb</p>