Nineth back Microsoft.Practices.Unity.Interception implementation of data set-based caching (for six, seven, eight-spoke of the specific concepts and configuration of the commentary)

Source: Internet
Author: User
Tags log4net connectionstrings

Back to Catalog

Concept

Microsoft.Practices.Unity.Interception is an interceptor, which is subordinate to the Microsoft.Practices.Unity composition, mainly to complete the function of AOP, and implementation of the AOP method interception (page tangent) is based on the IOC, we need to configure Related interfaces or types of IOC, and then in the production of objects, using Unity's method for dynamic production objects, your interception interceptor will also play a role!

Related Technologies

IOC: Inversion of controls (inversion of control, English abbreviation for IOC) is an important object-oriented programming principle to reduce the coupling problem of computer programs. Control inversion is also known as Dependency injection (Dependency injection, short di). The objects in the configuration will be injected into the project program dynamically, so that a function of the program can be dynamically switched.

AOP: Plane-oriented programming (also called aspect-oriented programming): Aspect Oriented Programming (AOP) is a hotspot in software development. AOP enables the isolation of parts of the business logic, which reduces the coupling between parts of the business logic, improves the reusability of the program, and improves the efficiency of development.

It is generally used to implement: logging, performance statistics, security control, transaction processing, exception handling and so on.

Persistence mode

My project.unitycaching component currently supports Microsoft.Practices.EnterpriseLibrary.Caching and Redis two data persistence methods, the former is also microsoft.practices. Enterpriselibrary part of the Enterprise Library, mainly for memory persistence (also can achieve file persistence), mainly used on a single Web server, the latter can be deployed separately to one or more servers, mainly to implement distributed cache, it is the future of big data in one direction.

Key Name composition

Cache Solution Name _ Namespaces _ The method name , where the cache solution name can be configured on its own, corresponding to the Cacheprojectname node in config, and the key corresponding to the value of the dictionary type, the dictionary key corresponding to the combination of the parameters of the method.

Related assemblies involved

IOC Infrastructure Library Assemblies

Redis Base Library Assemblies

Project.frameworks Self-encapsulated assemblies

Configuration for IOC,AOP in the configuration file
<configSections> <!--For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?linkid=237468 --<section name="EntityFramework"Type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, version=5.0.0.0, culture= Neutral, publickeytoken=b77a5c561934e089"requirepermission="false"/> <section name="log4net"Type="log4net. Config.log4netconfigurationsectionhandler, Log4net"/> <section name="cachingconfiguration"Type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, version=5.0.505.0, Culture=neutral, publickeytoken= 31bf3856ad364e35"/> <section name="Unity"Type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration "/> <section name="Redisconfig"Type="Redis.Client.RedisConfigInfo, Redis.client"/> </configSections> <redisconfig writeserverlist="127.0.0.1:6379"readserverlist="127.0.0.1:6379"Maxwritepoolsize=" -"Maxreadpoolsize=" -"autostart="true"Localcachetime=" the"recordelog="false"> </RedisConfig> <cachingconfiguration defaultcachemanager="Byteartretailcachemanager"> <cacheManagers> <add name="Byteartretailcachemanager"Type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, version=5.0.505.0, culture=neutral, publickeytoken=31bf3856ad364e35"expirationpollfrequencyinseconds=" -"maximumelementsincachebeforescavenging=" +"numbertoremovewhenscavenging="Ten"Backingstorename="Nullbackingstore"/> <!--expirationpollfrequencyinseconds: Expiration Time (seconds) Maximumelementsincachebeforescavenging: Maximum number of elements in buffer Numbertoremovewhenscavenging: Number of removal at one time-</cacheManagers> <backingStores> <add type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, version=5.0.505.0, Culture=neutral, publickeytoken= 31bf3856ad364e35"Name="Nullbackingstore"/> </backingStores> </cachingConfiguration> <unity xmlns="http://schemas.microsoft.com/practices/2010/unity"> <sectionextension type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension, Microsoft.Practices.Unity.Interception.Configuration"/> <container> <!--generic type injection, data warehousing service injection, can be achieved by EF,LINQ,ADO,MEMORY,FILE,NOSQL, etc.--<register type="Irepository.core.iunitofwork,irepository.core"mapto="nlayer_ioc_demo.entity.backgroundtestiocentities,nlayer_ioc_demo.entity"/> <!--using Redis as a persistent storage--<!--<register type="IRepository.Core.IRepository ' 1,irepository.core"mapto="Redis.Data.Core.RedisRepository ' 1,redis.data.core"/>--> <!--using SQL Server as persistent storage--<register type="IRepository.Core.IRepository ' 1,irepository.core"mapto="NLayer_IoC_Demo.DATA.backgroundRepositoryBase ' 1,nlayer_ioc_demo.data"/> <register type="IRepository.Core.IExtensionRepository ' 1,irepository.core"mapto="NLayer_IoC_Demo.DATA.backgroundRepositoryBase ' 1,nlayer_ioc_demo.data"/> <!--AOP injection--<extension type="interception"/> <register type="NLAYER_IOC_DEMO.BLL.IUSERSERVICE,NLAYER_IOC_DEMO.BLL"mapto="NLAYER_IOC_DEMO.BLL.USERSERVICE,NLAYER_IOC_DEMO.BLL"> <!--interface interception--<interceptor type="Interfaceinterceptor"/> <!--Cache injection--<interceptionbehavior type="project.unitycaching.cachingbehavior,project.unitycaching"/> </register> <register type="NLAYER_IOC_DEMO.BLL.ORDERSERVICE,NLAYER_IOC_DEMO.BLL"> <!--interface interception--<interceptor type="Virtualmethodinterceptor"/> <!--virtual method injection, generating derived classes to intercept, let's eliminate the time to set up the interface, good choice-<!--Transparent Proxy Interceptor-&L t;! --it is injected with all Virutal method, method,Interface, but it's poor performance--<!--cache injection--<interceptionbehavior type="project.unitycaching.cachingbehavior,project.unitycaching"/> </register> <register type="Project.InterceptionBehaviors.IHandle, Project.interceptionbehaviors"mapto="Project.InterceptionBehaviors.StandardHandle, Project.interceptionbehaviors"> <!--interface interception--<interceptor type="Interfaceinterceptor"/> <interceptionbehavior type="NLAYER_IOC_DEMO.BLL.AOP.LOGGERBEHAVIOR,NLAYER_IOC_DEMO.BLL"/> </register> </container> </unity> <connectionStrings> <add name="backgroundtestiocentities"connectionstring="metadata=res://*/background.csdl|res://*/background.ssdl|res://*/background.msl;provider= System.data.sqlclient;provider connection String=&quot;data source=.; Initial catalog=backgroundtestioc;persist security Info=true;user id=sa;password=zzl123; Multipleactiveresultsets=true; app=entityframework&quot;"Providername="System.Data.EntityClient"/> <add name="defaultconnection"connectionstring="Data source= (LocalDb) \v11.0;initial catalog=aspnet-nlayer_ioc_demo-20141024091423;integrated Security=SSPI; attachdbfilename=| Datadirectory|\aspnet-nlayer_ioc_demo-20141024091423.mdf"Providername="System.Data.SqlClient"/> </connectionStrings>
View CodeKey points to note when using
    1. The concept of service locator Servicelocator is introduced in the Unity component, which allows us to automatically navigate the bin directory without referencing the target assembly.
    2. For a redis-style cache, the cached entity class needs to be declared as a Serializable attribute.
    3. When implementing IOC,AOP, only the required assemblies are referenced, not all Microsoft.Practices.Unity components are introduced, and the required assemblies are automatically added to the bin directory of the UI project when the program is compiled.
    4. method to intercept this block there are three kinds, but transparentproxyinterceptor because of poor performance, we do not advocate the use of the project we mainly use virtualmethodinterceptor For the interception of virtual methods and Interfaceinterceptor for the interception of the interface, both ways have advantages, if the implementation of a single, you can directly use virtual method injection, which can save the code to write the interface.

Back to Catalog

Nineth back Microsoft.Practices.Unity.Interception implementation of data set-based caching (for six, seven, eight-spoke of the specific concepts and configuration of the commentary)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.