title: Service Locator Anti-Pattern Okay For Factory Registration
body: <p>I'm creating a REST framework,  and I'm wondering if it's okay to provide access to the service provider since it will be used in the Factory.  I have a generic service which has events that fire on Create and Update</p>
  
  <pre><code>public event Func&lt;object, TDTO, Task&gt; CreateEvent;
  
  protected virtual async Task OnCreated(TDTO dto)
  {
      await ServiceEventHandlerRule.OnServiceEvent(CreateEvent, this, dto);
  }
  
  public async Task&lt;TDTO&gt; Create(TDTO dto)
  {
      var entity = this.DtoToEntity(dto, new TEntity());
      this._context.Set&lt;TEntity&gt;().Add(entity);
  
      dto = await this.SaveEntity(entity);
      await OnCreated(dto);
      return dto;
  }
  </code></pre>
  
  <p>I'm registering Events on my sevices in a factory, Currently I'm exposing a <code>Func&lt;IServiceProvider, Object, TDto&gt;</code>  Event Registration looks like so, this occurs in my startup.cs:</p>
  
  <pre><code>var serviceConfig = new ServiceConfiuration&lt;User, UserDTO&gt;();
  serviceConfig.EventMapping.AddCreateEvent(async (sp, obj, dto) =&gt; {
      var hubTaskQueue = sp.GetService&lt;IHubServiceTaskQueue&gt;();
      hubTaskQueue.QueueCreate&lt;THub, TDTO&gt;(dto);
  });
  services.AddScopedRestService(serviceConfig);
  </code></pre>
  
  <p>Users will need access to a few extra dependencies for their events so I've given them access to the <code>IServiceProvider</code>,   </p>
  
  <p>What is the downside of using the Service Location Pattern During Registration?</p>
  
  <p>Should I mask IServiceProvider and make a few Generic Overload which will auto resolve their dependencies?  </p>