Outils pour utilisateurs

Outils du site


informatique:dotnet:entlib

Framework Enterprise Library (EntLib)

  • Petit nom: EntLib
  • Autre nom: Enterprise Library Blocks
  • Ancien nom: Application Blocks
  • inside Microsoft patterns & practices

Sur MSDN Solution Development Fundamentals:

Ses domaines fonctionnels sont :

  • Caching Application Block. Developers can use this application block to incorporate a cache in their applications. Pluggable cache providers are supported.
  • Cryptography Application Block. Developers can use this application block to incorporate hashing and symmetric encryption in their applications.
  • Data Access Application Block. Developers can use this application block to incorporate standard database functionality in their applications.
  • Exception Handling Application Block. Developers and policy makers can use this application block to create a consistent strategy for processing exceptions that occur throughout the architectural layers of enterprise applications.
  • Logging Application Block. Developers can use this application block to include standard logging functionality in their applications.
  • Policy Injection Application Block. Developers can use this application block to implement interception policies that can be used to streamline the implementation of common features, such as logging, caching, exception handling, and validation, across a system.
  • Security Application Block. Developers can use this application block to incorporate authorization and security caching functionality in their applications.
  • Unity Application Block. Developers can use this application block as a lightweight and extensible dependency injection container with support for constructor, property, and method call injection, as well as instance and type interception (via an extension).
  • Validation Application Block. Developers can use this application block to create validation rules for business objects that can be used across different layers of their applications.

Documentation

Unity

Dependencies Injection (DI)

  • Ancien nom: DIAB (Dependency Inject Application Block).

The Unity Application Block (Unity) is a lightweight, extensible dependency injection container that supports constructor injection, property injection, and method call injection. You can use it with Enterprise Library to generate both Enterprise Library objects and your own custom business objects. However, the Unity Application Block differs from the other application blocks included in Enterprise Library in several fundamental ways:

  • You can use the Unity Application Block as a stand-alone dependency injection mechanism that does not require Enterprise Library to be installed.
  • The Unity Application Block can use configuration information exposed through configuration files to prepare the container, but you can also use code to dynamically register dependencies at run time.
  • The Unity Application Block has no dependency on the Enterprise Library core or the Enterprise Library configuration system. It contains its own built-in mechanism for reading configuration—although, if appropriate, this information can come from the normal Enterprise Library configuration file.

Exemples

Exemple d'injection de dépendance. Ici on injecte un “IVehicule” dans un “Coursier” (le pauvre ;-)).

  <unity>
    <containers>
      <container>
        <types>
          <type type="UnityTest01.IVehicule, UnityTest01" mapTo="UnityTest01.Moto, UnityTest01" name="uneMoto" />
          <type type="UnityTest01.IVehicule, UnityTest01" mapTo="UnityTest01.Voiture, UnityTest01" name="uneVoiture" />
 
          <type type="UnityTest01.Coursier, UnityTest01" mapTo="UnityTest01.Coursier, UnityTest01" name="Marcel">
            <typeConfig >
              <property name="Vehicule" propertyType="UnityTest01.IVehicule, UnityTest01">
                <dependency name="uneVoiture" />
              </property>
            </typeConfig>
          </type>
 
          <type type="UnityTest01.Coursier,UnityTest01" mapTo="UnityTest01.Coursier, UnityTest01" name="Antoine">
            <typeConfig >
              <property name="Vehicule" propertyType="UnityTest01.IVehicule,UnityTest01">
                <dependency name="uneMoto" />
              </property>
            </typeConfig>
          </type>
        </types>
 
        <instances>
          <!--
          Je ne comprends pas que ce ne soit pas dans "instances" mais dans "types" que l'on créé les instances des objets.
 
          <add name="uneMoto" type="UnityTest01.Moto" value=""/>
          <add name="uneVoiture" type="UnityTest01.Voiture" value=""/>          
          <add name="unCoursier" type="UnityTest01.Coursier" value="">
            <property name="Vehicule" propertyType="UnityTest01.IVehicule">
              <value value="uneVoiture" />
            </property>
          </add>
          -->
        </instances>
 
      </container>
    </containers>
  </unity>
            UnityContainer container = new UnityContainer();
 
            UnityConfigurationSection section
              = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
            section.Containers.Default.Configure(container);
 
            Coursier coursierMarcel = container.Resolve<Coursier>("Marcel") as Coursier;
            Debug.WriteLine("coursierMarcel.Vehicule.WheelsCount: " + coursierMarcel.Vehicule.WheelsCount);
            this.textBox1.AppendText(String.Format("Marcel est équipé d'un véhicule à {0} roues.", coursierMarcel.Vehicule.WheelsCount) + Environment.NewLine);
 
            Coursier coursierAntoine = container.Resolve<Coursier>("Antoine") as Coursier;
            Debug.WriteLine("coursierAntoine.Vehicule.WheelsCount: " + coursierAntoine.Vehicule.WheelsCount);
            this.textBox1.AppendText(String.Format("Antoine est équipé d'un véhicule à {0} roues.", coursierAntoine.Vehicule.WheelsCount) + Environment.NewLine);

Doc

A éclaircir

Déclaration des objets avec Unity (type!=instance)

http://www.developpez.net/forums/d712302/dotnet/general-dotnet/entlib4-declaration-objets-unity/#post4141845

En fait je me demande pourquoi les objets sont déclarés dans la section “types” et pas dans la section “instances” ?? Du coup je trouve le schéma de Unity bien plus compliqué que celui de Spring.Net
Je suppose que Type c'est pour enregistrer mapper un type à un autre (mapper par exemple un IToto à un Toto). Quand tu fais un container.Resolve<IToto> il te renvoie un objet de type Toto.
Instance ça doit être pour mapper un type à une instance précise. Quand tu lui demande le type A il te renvoie l'instance que tu as enregistrés, et pas une nouvelle.

Extrait de la doc :

  • If you used the RegisterType method to register a type, Unity will create a new instance of the registered type during the first call the Resolve or ResolveAll method or when the dependency mechanism injects instances into other classes based on attributes or constructor parameters within that class. Subsequent requests will return the same instance.
  • If you used the RegisterInstance method to register an existing object, Unity will return this instance every time you call to the Resolve or ResolveAll method or when the dependency mechanism injects instances into other classes based on attributes or constructor parameters within that class.

Data Access Application Block (DAAB)

La partie DAAB de EntLib remplace dynamiquement SQLConnexion par OracleConnexion, ainsi que les commandes, transactions etc. Il remplace aussi la chaîne de connexions, il permet aussi le chiffrage des chaînes de connexion, etc.

AOP

Validation

informatique/dotnet/entlib.txt · Dernière modification : 19/05/2012 00:18 de 127.0.0.1

Sauf mention contraire, le contenu de ce wiki est placé sous les termes de la licence suivante : CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki