Currently I have into my ConfigureServices all the dependencies I inject

```
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddSingleton<IConfiguration>(Configuration);
     //injecting my dependenies here
     services.AddDependencies(Configuration);
 }

```

The thing is that I want to optimize the process below injecting things in parallel. Please see that what I want to optimize is the processing time of this method **AddDependencies**

```
public static IServiceCollection AddDependencies(this IServiceCollection services, IConfiguration configuration)
{
  services.RegisterTypes(configuration)
            .AddFluentValidationConfiguration()
            .AddAutomapperConfiguration();

  return services;
}

```

My approach at first was the following:

```
public static IServiceCollection AddDependencies(this IServiceCollection services, IConfiguration configuration)
    {
        var t1 = Task.Run(() => { services.RegisterTypes(configuration);});
        var t2 = Task.Run(() => { services.RegisterFluentValidation();});
        var t3 = Task.Run(() => { services.RegisterMappingsWithAutomapper();});

        Task.WhenAll(t1, t2, t3).Wait();

        return services;
    }

```

But sometimes I get an exception, my methods like RegisterTypes internally make calls like this

```
services.Register<ISmtpConfig, SmtpConfig>(lifeTime);

```

so the resource `services` is shared between multiple threads, I thought that putting a lock statement similar to this would fix the problem, but no

```
 private Object thisLock = new Object(); --> global variable  

 lock (thisLock)  
 {  
   services.Register<ISmtpConfig, SmtpConfig>(lifeTime);
 }

```

Can anyone put me into the right spot?