aspnet/DependencyInjection — pull request #142 by HaoK (2014-11-22 00:39:11+00:00)
Title: Basic extension to Add only if service has not been added

cc @davidfowl @divega @lodejard @halter73

Bare bones helper needed so frameworks can use this when replacing their GetDefaultServices with AddXXX methods to prevent duplicates. Most GetDefaultServices are using Describer, EF is the outlier, but for them to support config based service replacement, they probably will need to change as well...

Example:

```
public static IServiceCollection AddOptions([NotNull]this IServiceCollection services, IConfiguration config = null)
{
var describe = new ServiceDescriber(config ?? new Configuration());
services.AddIfMissing(describe.Singleton(typeof(IOptions<>), typeof(OptionsManager<>)));
return services;
}
```

AddIfMissing is pretty meh as far as names go...

Some other ideas?
- AddIfNotPresent
- AddIfNotDupe
- AddIfNew
- AddNew
- AddOnlyIfMissing
- AddOnlyIfNew
- Ensure