title: How to allow for optional services with Microsoft.Extension.DependencyInjection?
body: <p>I am playing around with ASP.NET Core on my own hobby project, I want to create a framework that will be consumed by a developer, and I want to allow optional service and use defaults if they are not registered.</p>
  
  <p>I am getting the <code>Unable to resolve service for type 'XXX'</code> error, but I would prefer the DI to return <code>null</code> rather then throw an exception.
  I want to allow for optional services, so if a service is found, use that in the constructor, if not found, pass null into the constructor.</p>
  
  <p>In my implementation I have:</p>
  
  <pre><code>public IServiceManager(IService service, ...)
  {
      _service = service ?? new DefaultService();
      ...
  }
  </code></pre>
  
  <p>So as you can see, if the service cannot be found (null) use the default.
  Perhaps I am misunderstanding how DI works. Perhaps I could use a factory to do this instead?
  However, in my system I using default services when non is provided will be a common occurrence, so I need a solution that doesn't require the consumer of the API to register a service.</p>
  
  <p>Is there a way to configure ASP.NET Core DI to return null rather then throw an exception?</p>