private static IServiceProvider GetServiceProvider(GitVersionOptions gitVersionOptions, ILog log = null, IGitRepository repository = null, IFileSystem fileSystem = null, IEnvironment environment = null) { return(ConfigureServices(services => { if (log != null) { services.AddSingleton(log); } if (fileSystem != null) { services.AddSingleton(fileSystem); } if (repository != null) { services.AddSingleton(repository); } if (environment != null) { services.AddSingleton(environment); } var options = Options.Create(gitVersionOptions); services.AddSingleton(options); services.AddSingleton(RepositoryExtensions.ToGitRepositoryInfo(options)); })); }
private static IServiceProvider GetServiceProvider(GitVersionOptions gitVersionOptions, ILog?log = null, IGitRepository?repository = null, IFileSystem?fileSystem = null, IEnvironment?environment = null) => ConfigureServices(services => { services.AddSingleton <IGitVersionContextFactory, GitVersionContextFactory>(); services.AddSingleton(sp => { var options = sp.GetRequiredService <IOptions <GitVersionOptions> >(); var contextFactory = sp.GetRequiredService <IGitVersionContextFactory>(); return(new Lazy <GitVersionContext>(() => contextFactory.Create(options.Value))); }); if (log != null) { services.AddSingleton(log); } if (fileSystem != null) { services.AddSingleton(fileSystem); } if (repository != null) { services.AddSingleton(repository); } if (environment != null) { services.AddSingleton(environment); } var options = Options.Create(gitVersionOptions); services.AddSingleton(options); services.AddSingleton(RepositoryExtensions.ToGitRepositoryInfo(options)); });