Thursday, April 30, 2015

IoC Inversion Of abbreviation of Control, IoC is a concept / model / principles in developing large


In the article we had HelloWorld project Bootstrapper class simple, but to use the IoC in Caliburn.Micro we need to rewrite this class. Through this article ice we will understand more about the naming of a class in how to use IoC Caliburn and ...
IoC Inversion Of abbreviation of Control, IoC is a concept / model / principles in developing large complex applications, to reduce the dependence between floors, the components ice and the class by playing Island control flow of the application, we can understand that the IOC is a supplier (or container provider), ice in fact when a large Project, ice having multiple Component, Module, Class ... but that is normal managing and initializing objects will gradually scale complex projects, thus IoC is the optimal solution for managing, creating ice and providing ice the object as necessary.
In fact, the issue of managing the creation and destroy objects with the use IoC probably need a little miracle, because that one will liberate objects if you do not liable initialize them? The main point is that it provides an IoC framework as a software-called Container. Like the name implies it, the container will know the ingredients needed for your application and try to be smart enough to understand the ingredients you want. This happens when you perform a query and request it returns a success-section which is one of the entities resident in the container. This is the meaning of IoC. No longer the instance of the class is created using the constructor is defined in the class available in the traditional way (new A ();). Instead we will register them in the container and if necessary we simply query the container then it will give you an instance of the component that you require.
Most of IoC is the OpenSource community development is key, Microsoft unofficial fine model for the .NET platform (they have other ways similar to some problems Module) because basically it is still a something ice new and vague for most of the .NET approach. IoC lead to a better ice structured, modular ice capabilities, the ability ice to make a profit and maintain better application response. Once this was discovered, the programmer will never return ice to the old way was to build software. II> Configure the Bootstrapper
To use IoC we need to care much about class Bootstrapper (view and reuse the HelloWorld project), the class we want to be the Export IoC management, if that is one class implements an interface, it must Export clear and when GetInstance to query for more information. For example [code language = "csharp"] {} // internal interface Implement iPage of iPage [Export ("PageOne", typeof (iPage))] internal class PageOne: iPage {} [Export ("PageTwo", typeof (iPage ))] internal class PageTwo: {} // ------------------------------------ iPage internal interface ice {} // Implement INews of INews [Export (typeof (INews))] internal class News: INews {} [/ code]
Bootstrapper.cs class [code language = "csharp"] internal sealed ice class Bootstrapper: {private BootstrapperBase CompositionContainer _container; /// <Summary> /// /// Constructor </ summary> public Bootstrapper () {StartRuntime (); } /// <Summary> /// Override to configure the IoC framework and container của setup. /// </ Summary> protected override void Configure () {_container = new CompositionContainer (new AggregateCatalog (AssemblySource.Instance.Select (x => new AssemblyCatalog (x)). OfType <ComposablePartCatalog> ())); var CompositionBatch batch = new (); batch.AddExportedValue <IWindowManager> (new WindowManager ()); batch.AddExportedValue <IEventAggregator> (new EventAggregator ()); batch.AddExportedValue (_container); _container.Compose (batch); } /// <Summary> /// Gets the instance. /// </ Summary> /// <param name = "serviceType"> Type of the service. </ Param> /// <param name = "key"> The key. </ Param> /// <returns > </ returns> /// <exception cref = "System.Exception"> </ exception> protected override object GetInstance (Type serviceType, string key) {var contract = string.IsNullOrEmpty (key)? AttributedModelServices.GetContractName (serviceType): key; var exports ice = _container.GetExportedValues <object> (contract); var = exports as enumerable object [] ?? exports.ToArray (); if (enumerable.Any ()) return enumerable.First (); throw new Exception (String.Format ("Could not locate any instances of contract {0}.", contract)); } /// <Summary> /// Gets all instances. /// </ Summary> /// <param name = "serviceType"> Type of the service. </ Param> /// <returns> </ returns> protected override IEnumerable <object> GetAllInstances (Type servic

No comments:

Post a Comment