Category Archives: Software Engineering

An IoC Conundrum: Looking for feedback

Today at work, my boss and I were brainstorming on the best way to use IoC across all our code. During this, he proposed an idea for using IoC that at first made me feel uneasy with the way it was being used. But the more I think about it, the more I am amazed by its design. Let me set this up for you and the best way is with pictures.

Note: The code examples given here are not functional and just provided to give a rough idea of what is intended.

Explanation: 

  • The BaseLib is a library that contains all the interfaces we define. It also contains the CDepInjection class.
  • The CDepInjection class contains a static Register method that will find an assembly that corresponds to an interface and using Reflection, load it.
  • The Database library contains a CDatabase class with a static constructor that will be called from the previous step when the Database library is reflected and loaded. See image below.

Benefits:

  • By having all the interfaced in BaseLib, we are programming against an interface.
  • By having the CDepInjection class in BaseLib, there is only 1 place we need to update code and only 1 dll that we will need to deploy in production should changes be needed. (Note: We could have 100 servers running 100 application each and they may be windows services, web services, asp.net mvc apps, windows forms apps, console apps etc.).
  • By making a change in CDepInjection and telling it to map an interface name to the appropriate assembly and class and having the RegisterType be in the CDatabase class, we can create a new database class, CNoSqlDatabase in another assembly, deploy it, make a change to BaseLib by telling it to now map IDatabase to the CNoSqlDatabase and then deploy that to all our servers GAC. Now, everything will use the new CNoSQLDatabase.

Concerns I have:

  • Using a static constructor in CDatabase means that it will be called one per process and only when the assembly is loaded in the Register(..) method of CDepInjection. I’m not convinced that a static constructor would be the best thing to do. In essence, aren’t we just abstracting the mappings that would go in a config file and putting them into BaseLib instead of an app.config of BaseLib?
  • Resolving parent-child would necessitate having to call register in the ‘main’ method of all our applications. For instance, if CDatabase was going to need logging, it would have to call Register(“ILogging”) in the static constructor above the Container.RegisterType<IDatabase, CDatabase>() call.

I would very much appreciate a critique of this design. Thank you.

Advertisements
Tagged , , , , , , , ,

Developer Professionalism

There are numerous articles on the net about “developer professionalism” but I keep coming back to “Software Engineering Code of Ethics and Professional Practice“. You see, just about anyone can call themselves a developer, read a few books, accrue work experience at sub-par companies (those that do not demand professionalism) and end up as part of your organization.

As a professional in charge of hiring, it is your responsibility, to find developers who meet a certain level of professionalism. Junior developers are rarely held up to the same standards and I feel this does them a disservice. There are some things the junior dev will not be able to talk about but asking them questions like, “Give me an example of how you took responsibility for your code/work?” is a good way to get them talking about ethics and to find out just how professional they are. I have rarely come across any question that tried to ascertain your professionalism in interviews and that is both sad and scary.

If I find a problem with your code that would take you 10 min to fix and take me 30, don’t ever pass your faulty code to me to fix because you’re busy. Take responsibility [1.01, 6.08]. Fix it yourself.  And on the other side of the coin, if you find fault with my code, bring it to me to fix. Give me the chance to learn what I did wrong so that I don’t make the same mistake again.

So the next time you run into a problem, be it hiring a new dev, or an issue in code, ask yourself, “What would a professional dev do?”

Tagged , , ,