vendredi 3 mars 2017

Is resolving a service in Startup.cs a service locator pattern?

I've red Service Locator: roles vs mechanics by Mark Seemann and I can't decide about something. Is this GetRequiredService method, which is used in ConfigureServices method in Startup.cs (which is the composition root if I'm understanding it correctly), a service locator:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();

        services.AddScoped<IRepository, MyRepository>();

        services.AddAuthorization(options =>
        {
            var myPolicy = services.BuildServiceProvider().GetRequiredService<IRepository>().GetMyPolicy();

            options.AddPolicy("MyPolicy", policy => policy.AddRequirements(myPolicy));
        });
    }

Aucun commentaire:

Enregistrer un commentaire