CopyPastor

Detecting plagiarism made easy.

Score: 0.7595309615135193; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2019-02-13
by TanvirArjel

Original Post

Original - Posted on 2018-04-06
by Sibeesh Venu



            
Present in both answers; Present only in the new answer; Present only in the old answer;

> What does these errors means ?
These error means that you are using the services through constructor Dependency Injection but you have not registered those services to DI resolver.
> What will be the correct configuration here ?
What you have done is the correct way to resolve services.
>What is the way to not to add n number of repository as service here?
You can extend the `IServiceCollection` as follows in a separate file.
public static class ServiceCollectionExtensions { public static IServiceCollection AddCustomServices(this IServiceCollection services, IConfiguration configuration) {
services.AddSingleton<IUnitOfWork, UnitOfWork>(); services.AddSingleton<IOrderRepository, OrderRepository>(); services.AddSingleton<ICustomerRepository, CustomerRepository>();
return services; } }
Then in the startup class as follows:
services.AddCustomServices(Configuration);

I was having a different problem, and yeah the parameterized constructor for my controlleror was already added with the correct interface. What I did was something straightforward. I just go to my `startup.cs` file, where I could see a call to register method.
public void ConfigureServices(IServiceCollection services) { services.Register(); } In my case, this `Register` method was in a separate class `Injector`. So I had to add my newly introduced Interfaces there.
public static class Injector { public static void Register(this IServiceCollection services) { services.AddTransient<IUserService, UserService>(); services.AddTransient<IUserDataService, UserDataService>(); } }
If you see, the parameter to this function is `this IServiceCollection`
Hope this helps.

        
Present in both answers; Present only in the new answer; Present only in the old answer;