Does this violates open/closed principle?

0

Issue

I made a webapi with .NET Core and I have a "Startup" class. This class has a "ConfigureServices" method that says:

// This method gets called by the runtime. Use this method to add services to the container.

But every time i add a new service, i need to "modify" this method, but it violates the open/closed principle.

If I use use and "IF" and "ELSE" criteria to do the same thing as I am modifying this method.

So what do you think about this?

Solution

It is quite the opposite. You are extending the method inside your own Startup, not modifying the base Startup. This article from wikipedia clearly states that in order to comply to open/closed principle

software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification

I didn’t quite understand what you mean with the if/else part.

Answered By – markovic-m

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More