Review: Microsoft N Layer App Sample, Part IV-IoC FTW
Join the DZone community and get the full member experience.
Join For Freecontinuing my review of http://microsoftnlayerapp.codeplex.com/ , an official guidance (shows up at: http://msdn.microsoft.com/es-es/architecture/en ) which people are expected to read and follow.
while investigating how they are implementing ioc, i found:
/// <summary> /// configure root container.register types and life time managers for unity builder process /// </summary> /// <param name="container">container to configure</param> void configurerootcontainer(iunitycontainer container) { // take into account that types and mappings registration could be also done using the unity xml configuration //but we prefer doing it here (c# code) because we'll catch errors at compiling time instead execution time, //if any type has been written wrong. //register repositories mappings container.registertype<iproductrepository, productrepository>(new transientlifetimemanager()); container.registertype<iorderrepository, orderrepository>(new transientlifetimemanager()); container.registertype<ibankaccountrepository, bankaccountrepository>(new transientlifetimemanager()); container.registertype<icustomerrepository, customerrepository>(new transientlifetimemanager()); container.registertype<icountryrepository, countryrepository>(new transientlifetimemanager()); //register application services mappings container.registertype<isalesmanagementservice, salesmanagementservice>(new transientlifetimemanager()); container.registertype<icustomermanagementservice, customermanagementservice>(new transientlifetimemanager()); container.registertype<ibankingmanagementservice, bankingmanagementservice>(new transientlifetimemanager()); //register domain services mappings container.registertype<ibanktransferdomainservice, banktransferdomainservice>(new transientlifetimemanager()); //register crosscuting mappings container.registertype<itracemanager, tracemanager>(new transientlifetimemanager()); }
just to figure out how ridiculous this is, let me show you the entire infrastructure required to support ioc in this application:
yes, they abstracted the inversion of control container . i think that if you need to do that, it is pretty clear that you don’t really get what ioc is all about.
maybe , if you are a framework, you need to abstract the container, but you don't need to do that if you are an application (which this is supposed to be) and you certainly don't write your own, that is why commonservicelocator is here.
then again, the code is absolutely littered with things like:
so i guess that it is not really a surprise.
what is a surprise is that they are catching nullreferenceexception. you are not supposed to catch this exception . this is an indication that you have some problem with your code, not that you have some invalid argument issue.
Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
DZone's Article Submission Guidelines
-
How to LINQ Between Java and SQL With JPAStreamer
-
Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
-
An Overview of Kubernetes Security Projects at KubeCon Europe 2023
Comments