Installing an ASP.Net MVC Controller

I am looking for suggestions on good ways to develop a new ASP.NET Mvc project. It is medium in size and relatively simple in structure. I originally used Spring.Net to connect service objects to the correct constructors, but now the manual has told me that Spring.Net or any other IOC container should not be used in our environment.

I have a bit of trouble figuring out how to do this without DI. I would like to be able to assign service implementations to controllers in such a way as to ensure a low level of communication between controllers and services and to limit the reliability of controllers when implementing individual services. I think my question boils down to the fact that I'm not sure where I have to manually connect my application in the MVC model.

Any suggestions?

+4
source share
5 answers

First of all, I would question why the management instructed you to not use a template and tools that would allow you to get free communication and dependence. Is this something you can discuss and discuss?

With an IoC container, it is trivial to implement IControllerFactory , which allows controllers from the container and implements the necessary services.

MVC 3 has an IDependencyResolver that you can use to achieve poor communication (using the Locator template / anti-Service Locator template) than creating instances directly inside the controllers; this interface was designed for use with an IoC container, although in reality it would be a poorer replacement in itself.

+4
source

Since you are using ASP.NET MVC 3, you can write a custom dependency resolver . Of course, you will still design your controllers using the interfaces in your constructors to loosen the connection between the layers. And then in the custom dependency converter, to satisfy the ridiculous requirements that were imposed on you, you will have to manually say that when you have ISomeService , you return an instance of SomeServiceImpl . You know that the things that object containers and DI frameworks already do for you. Therefore, you basically have to reinvent multiple wheels. By the way, Iyende wrote about how you could create a custom IoC container in 15 lines of code , but of course, this is not the reason why you should ever do something like this.

People who impose such requirements must be brought to justice and sentenced to never have to approach the design of the application. The imposition of such a requirement illustrates some general lack of knowledge about best practices in application design. These people should be advised before they bring additional damage to the company.

So, just explain to people that when reinventing the wheels, there are 2 errors:

  • you will spend a lot of time on what has already been done by someone else.
  • you will make mistakes since you will not take into account all cases of edges that have been taken into account by someone who designs reusable DI frames.

At the end of the day, you will send the application later on schedule (since you would take the time to write a plumbing code), and even worse you will send an application that will contain potential errors.

Conclusion: expensive and buggy product. Your leadership must have really passed out :-)

Conclusion 2: use the existing DI structure. Management does not even notice, because they do not seem to understand the technical aspects of the application, imposing such requirements.

+5
source

Does your boss have sharp hair? http://www.dilbert.com/

You could save some time using http://unitymvc3.codeplex.com/ , instead of writing your own custom dependency converter. It can be downloaded through Nuget http://nuget.org/ . If you use an IOC container such as this and use constructor injection, you will find that your unit tests are much easier to write. This assumes that your manager believes in unit testing ;-) Good luck!

0
source

the manual told me that Spring.Net or any other IOC container should not be used in our environment.

Management tells you that you are not allowed to write free related, testable and highly supported applications, that’s what they tell you. This is a strange limitation.

Injection injection is an advanced technology that many developers do not understand. However, management will never understand this, and it is not their task to understand this. They may dictate the type of technology (such as .NET or Java) because it affects the staff they need to hire, but when they begin to dictate low-level drilldown details that prevent you from writing descent software, your company is heading for disaster.

Leave this company now!

Another option: source code Simple injector . The code base is small enough (about 500 lines, just use the SimpleInjector.NET project) to be able to copy it to a local project (and the license allows it). So your own local DI container, but fully tested :-)

Good luck.

0
source

You need a new home. There are many organizations looking for talented engineers who care about quality and scalable architectures. Make sure you find the right one and they will be happy to find you.

Avoid the temptation to save your current team from their own shortsightedness. From your descriptions it sounds like you are already a pariah, despite your talents. Accept the fact that they will not listen to you.

The best strategy is to fake being a newly born player on the team. Build your MVC project exactly as your boss asked, i.e. Dumb way, without sharing problems. When version 1 of your project is completed and passes the QA (if you have a QA), your boss will probably think that he is justified. Be prepared for this reaction.

The best hope you have for enlightening your current team members is to show them that even if you create the software using the same mute methods that they feel comfortable with, you can still control the rings around them. It can be fun. Then, when you leave, you give them the opportunity to think about the possibility that you have done something. They can either take this chance or choose constant comfort, but that will not be your problem.

0
source

All Articles