diff --git a/NuGet.config b/NuGet.config
index cf37d041..4d736c19 100644
--- a/NuGet.config
+++ b/NuGet.config
@@ -1,7 +1,7 @@
-
+
diff --git a/README.md b/README.md
index d2c06e17..33fe45ea 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,6 @@ THE SPRING.NET FRAMEWORK
---------------------------------------------------------
http://www.springframework.net/
-
## INTRODUCTION
Spring.NET contains:
@@ -19,23 +18,29 @@ Spring.NET contains:
* ASP.NET MVC and ASP.NET WebAPI Framework
* Dependency Injection for MVC (includin WebAPI).
* Declarative transaction management abstraction
- * Declarative transaction management via use of common XML configuration and attributes across different transaction APIs
+ * Declarative transaction management via use of common XML configuration and attributes across different transaction
+ APIs
* ADO.NET framework
- * Simplifies use of ADO.NET. DAO support classes and integration with Spring's declarative transaction management functionality
+ * Simplifies use of ADO.NET. DAO support classes and integration with Spring's declarative transaction management
+ functionality
* Portable Service Abstractions
- * Export plain .NET objects via .NET Remoting, Web Service or .NET Serviced Component and create client side proxies based on endpoint URL and service interface.
+ * Export plain .NET objects via .NET Remoting, Web Service or .NET Serviced Component and create client side proxies
+ based on endpoint URL and service interface.
* NHibernate Integation
- * NHibernate 5 integration to simplify use of NHibernate and participate in Spring's declarative transaction management functionality.
+ * NHibernate 5 integration to simplify use of NHibernate and participate in Spring's declarative transaction
+ management functionality.
* ASP.NET AJAX Integration
* Exporter to expose plain object on which Dependency Injection and AOP have been applied to JavaScript.
* NUnit and MSTest integration
- * Provides Dependency Injection of test cases and Spring container loading and caching. . Data access and transaction management features aid with integration testing.
+ * Provides Dependency Injection of test cases and Spring container loading and caching. . Data access and
+ transaction management features aid with integration testing.
* WCF integration
* Provides Dependency Injection and applicatin of AOP advice to WCF services
* Quartz integration
* Configure Quartz jobs using dependency injection and Spring's transactional support to persist job details
* MSMQ integration
- * Simplifies the use MSMQ by providing helper classes for message sending and receiving. Integrates with Spring's transaction management features.
+ * Simplifies the use MSMQ by providing helper classes for message sending and receiving. Integrates with Spring's
+ transaction management features.
* NMS integration
* Simplifies the use of NMS by providing helper classes for message sending and receiving.
* TIBCO EMS integration
@@ -43,7 +48,8 @@ Spring.NET contains:
* NVelocity integration
* Simplifies the use of configuring NVelocity
-Spring.NET is a port of the Java based Spring Framework. In turn, the Java/J2EE Spring Framework is based on code published in "Expert One-on-One J2EE Design and Development" by Rod Johnson (Wrox, 2002).
+Spring.NET is a port of the Java based Spring Framework. In turn, the Java/J2EE Spring Framework is based on code
+published in "Expert One-on-One J2EE Design and Development" by Rod Johnson (Wrox, 2002).
## SUPPORTED .NET FRAMEWORK VERSIONS
@@ -64,7 +70,7 @@ Release contents:
* `doc` contains reference documentation, MSDN-style API help, and the Spring.NET xsd.
* `examples` contains sample applications.
* `build-support` contains additonal applications need to build using NAnt as some convenience
- VS.NET solution files.
+ VS.NET solution files.
* `dev-support` contains 'developer support' tools and code, such as solution templates for VS.NET
debug build is done using /DEBUG:full and release build using /DEBUG:pdbonly flags.
@@ -75,74 +81,89 @@ Latest info is available at the public website: http://www.springframework.net/
The Spring Framework is released under the terms of the Apache Software License (see license.txt).
-
## DISTRIBUTION DLLs
-The "bin" directory contains the following distinct dll files for use in applications. Dependencies are those other than on the .NET BCL.
+The "bin" directory contains the following distinct dll files for use in applications. Dependencies are those other than
+on the .NET BCL.
-* __Spring.Core__ (~765 KB) [](https://www.nuget.org/packages/Spring.Core/) [](#)
+* __Spring.Core__ (~765
+ KB) [](https://www.nuget.org/packages/Spring.Core/) [](#)
* Contents: Inversion of control container. Collection classes.
* Dependencies: Common.Logging
-* __Spring.Aop__ (~150 KB) [](https://www.nuget.org/packages/Spring.Aop/) [](#)
+* __Spring.Aop__ (~150
+ KB) [](https://www.nuget.org/packages/Spring.Aop/) [](#)
* Contents: Abstract Oriented Programming Framework.
* Dependencies: Spring.Core, Common.Logging
-* __Spring.Data__ (~320 KB) [](https://www.nuget.org/packages/Spring.Data/) [](#)
+* __Spring.Data__ (~320
+ KB) [](https://www.nuget.org/packages/Spring.Data/) [](#)
* Contents: Transaction and ADO.NET Framework.
* Dependencies: Spring.Core, Spring.Aop
-* __Spring.Data.NHibernate5__ (~90 KB) [](https://www.nuget.org/packages/Spring.Data.NHibernate5/) [](#)
+* __Spring.Data.NHibernate5__ (~90
+ KB) [](https://www.nuget.org/packages/Spring.Data.NHibernate5/) [](#)
* Contents: NHibernate 5.x integration
* Dependencies: Spring.Core, Spring.Aop, Spring.Data, NHibernate
-* __Spring.Services__ (~70 KB) [](https://www.nuget.org/packages/Spring.Services/) [](#)
+* __Spring.Services__ (~70
+ KB) [](https://www.nuget.org/packages/Spring.Services/) [](#)
* Contents: Web Services, Remoting, and Enterprise Component based services.
* Dependencies: Spring.Core, Spring.Aop
-* __Spring.Web__ (~165 KB) [](https://www.nuget.org/packages/Spring.Web/) [](#)
+* __Spring.Web__ (~165
+ KB) [](https://www.nuget.org/packages/Spring.Web/) [](#)
* Contents: ASP.NET based Web Application Framework.
* Dependencies: Spring.Core, Spring.Aop
-* __Spring.Web.Extensions__ (~8 KB) [](https://www.nuget.org/packages/Spring.Web.Extensions/) [](#)
+* __Spring.Web.Extensions__ (~8
+ KB) [](https://www.nuget.org/packages/Spring.Web.Extensions/) [](#)
* Contents: ASP.NET AJAX Integartion
* Dependencies: Spring.Core, Spring.Aop, System.Web.Extensions
-* __Spring.Web.Mvc5__ (~8 KB) [](https://www.nuget.org/packages/Spring.Web.Mvc5/) [](#)
+* __Spring.Web.Mvc5__ (~8
+ KB) [](https://www.nuget.org/packages/Spring.Web.Mvc5/) [](#)
* Contents: ASP.NET MVC5 and WebAPI Integartion
* Dependencies: Spring.Core, Spring.Web
-* __Spring.Testing.NUnit__ (~24 KB) [](https://www.nuget.org/packages/Spring.Testing.NUnit/) [](#)
+* __Spring.Testing.NUnit__ (~24
+ KB) [](https://www.nuget.org/packages/Spring.Testing.NUnit/) [](#)
* Contents: NUnit Integration
* Dependencies: Spring.Core, Spring.Data, NUnit
-* __Spring.Testing.Microsoft__ (~24 KB) [](https://www.nuget.org/packages/Spring.Testing.Microsoft/) [](#)
+* __Spring.Testing.Microsoft__ (~24
+ KB) [](https://www.nuget.org/packages/Spring.Testing.Microsoft/) [](#)
* Contents: MSTest Integration
* Dependencies: Spring.Core, Spring.Data, MSTest
-* __Spring.Messaging__ (~65 KB) [](https://www.nuget.org/packages/Spring.Messaging/) [](#)
+* __Spring.Messaging__ (~65
+ KB) [](https://www.nuget.org/packages/Spring.Messaging/) [](#)
* Contents: MSMQ Integration
* Dependencies: Spring.Core, Spring.Data, System.Messaging
-* __Spring.Messaging.Nms__ (~100 KB) [](https://www.nuget.org/packages/Spring.Messaging.Nms/) [](#)
+* __Spring.Messaging.Nms__ (~100
+ KB) [](https://www.nuget.org/packages/Spring.Messaging.Nms/) [](#)
* Contents: NMS Integration
* Dependencies: Spring.Core, Spring.Data, Apache NMS
-* __Spring.Scheduling.Quartz3__ (~44 KB) [](https://www.nuget.org/packages/Spring.Scheduling.Quartz3/) [](#)
+* __Spring.Scheduling.Quartz3__ (~44
+ KB) [](https://www.nuget.org/packages/Spring.Scheduling.Quartz3/) [](#)
* Contents: Quartz32.x Integration
* Dependencies: Spring.Core, Spring.Data, Quartz
-* __Spring.Template.Velocity__ (~44 KB) [](https://www.nuget.org/packages/Spring.Template.Velocity/) [](#)
+* __Spring.Template.Velocity__ (~44
+ KB) [](https://www.nuget.org/packages/Spring.Template.Velocity/) [](#)
* Contents: NVelocity Integration
* Dependencies: Spring.Core, NVelocity
-
## WHERE TO START?
Documentation can be found in the "docs" directory:
+
* The Spring reference documentation
Documented sample applications can be found in "examples":
+
* IoCQuickStart.MovieFinder - A simple example demonstrating basic IoC container behavior.
* IoCQuickStart.AppContext - Show use of various IApplicationContext features.
* IoCQuickStart.EventRegistry - Show use of loosely coupled eventing features.
@@ -166,7 +187,8 @@ Documented sample applications can be found in "examples":
VS.NET
------
-Visual Studio 2022 is required to open and build the solution. The free community version of Visual Studio should suffice.
+Visual Studio 2022 is required to open and build the solution. The free community version of Visual Studio should
+suffice.
## Acknowledgements
diff --git a/build-support/nuke-build/Build.GitHubActions.cs b/build-support/nuke-build/Build.GitHubActions.cs
index 698e3186..f61ff311 100644
--- a/build-support/nuke-build/Build.GitHubActions.cs
+++ b/build-support/nuke-build/Build.GitHubActions.cs
@@ -5,4 +5,4 @@ public partial class Build
Target Ci => _ => _
.DependsOn(Compile, Test, Pack)
.Executes();
-}
\ No newline at end of file
+}
diff --git a/build-support/nuke-build/Build.Publish.cs b/build-support/nuke-build/Build.Publish.cs
index 4bf63ae0..205568b6 100644
--- a/build-support/nuke-build/Build.Publish.cs
+++ b/build-support/nuke-build/Build.Publish.cs
@@ -3,7 +3,6 @@ using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
-
using static Nuke.Common.Tools.DotNet.DotNetTasks;
public partial class Build
@@ -39,5 +38,4 @@ public partial class Build
bool PushCompleteOnFailure => true;
int PushDegreeOfParallelism => 5;
-
}
diff --git a/build-support/nuke-build/Build.Test.cs b/build-support/nuke-build/Build.Test.cs
index cfdc1622..fd1a0f5e 100644
--- a/build-support/nuke-build/Build.Test.cs
+++ b/build-support/nuke-build/Build.Test.cs
@@ -1,21 +1,15 @@
using System.Linq;
using Nuke.Common;
using Nuke.Common.Tools.DotNet;
-
using static Nuke.Common.Tools.DotNet.DotNetTasks;
public partial class Build
{
- [Parameter]
- readonly bool TestFull = false;
- [Parameter]
- readonly bool TestIntegrationData = false;
- [Parameter]
- readonly bool TestIntegrationEms = false;
- [Parameter]
- readonly bool TestIntegrationNms = false;
- [Parameter]
- readonly bool TestIntegrationMsMq = false;
+ [Parameter] readonly bool TestFull = false;
+ [Parameter] readonly bool TestIntegrationData = false;
+ [Parameter] readonly bool TestIntegrationEms = false;
+ [Parameter] readonly bool TestIntegrationNms = false;
+ [Parameter] readonly bool TestIntegrationMsMq = false;
Target Test => _ => _
.DependsOn(Restore)
@@ -55,5 +49,4 @@ public partial class Build
});
}
});
-
-}
\ No newline at end of file
+}
diff --git a/build-support/nuke-build/Build.cs b/build-support/nuke-build/Build.cs
index 412f9552..995fb056 100644
--- a/build-support/nuke-build/Build.cs
+++ b/build-support/nuke-build/Build.cs
@@ -27,17 +27,13 @@ partial class Build : NukeBuild
/// - JetBrains Rider https://nuke.build/rider
/// - Microsoft VisualStudio https://nuke.build/visualstudio
/// - Microsoft VSCode https://nuke.build/vscode
+ public static int Main() => Execute(x => x.Compile);
- public static int Main () => Execute(x => x.Compile);
+ [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
- [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
- readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
+ [Parameter("Build EMS")] readonly bool BuildEms = false;
- [Parameter("Build EMS")]
- readonly bool BuildEms = false;
-
- [Parameter("Version")]
- readonly string ProjectVersion = "3.1.0";
+ [Parameter("Version")] readonly string ProjectVersion = "3.1.0";
[Solution] readonly Solution Solution;
[GitRepository] readonly GitRepository GitRepository;
@@ -180,35 +176,10 @@ partial class Build : NukeBuild
var binDirectory = RootDirectory / "bin";
binDirectory.CreateOrCleanDirectory();
- var moduleNames = new[]
- {
- "Common.Logging",
- "Common.Logging.Core",
- "Spring.Core",
- "Spring.Aop",
- "Spring.Data",
- "Spring.Data.NHibernate*",
- "Spring.Web",
- "Spring.Web.Mvc5",
- "Spring.Web.Extensions",
- "Spring.Services",
- "Spring.Testing.NUnit",
- "Spring.Testing.Microsoft",
- "Spring.Messaging.Ems",
- "Spring.Messaging.Nms",
- "Spring.Messaging",
- "Spring.Scheduling.Quartz3",
- "Spring.Template.Velocity",
- "Spring.Web.Conversation.NHibernate5",
- };
+ var moduleNames = new[] { "Common.Logging", "Common.Logging.Core", "Spring.Core", "Spring.Aop", "Spring.Data", "Spring.Data.NHibernate*", "Spring.Web", "Spring.Web.Mvc5", "Spring.Web.Extensions", "Spring.Services", "Spring.Testing.NUnit", "Spring.Testing.Microsoft", "Spring.Messaging.Ems", "Spring.Messaging.Nms", "Spring.Messaging", "Spring.Scheduling.Quartz3", "Spring.Template.Velocity", "Spring.Web.Conversation.NHibernate5", };
var patterns = moduleNames
- .SelectMany(x => new []
- {
- "**/" + Configuration + "/**/" + x + ".dll",
- "**/" + Configuration + "/**/" + x + ".xml",
- "**/" + Configuration + "/**/" + x + ".pdb"
- })
+ .SelectMany(x => new[] { "**/" + Configuration + "/**/" + x + ".dll", "**/" + Configuration + "/**/" + x + ".xml", "**/" + Configuration + "/**/" + x + ".pdb" })
.ToArray();
foreach (var file in BuildDirectory.GlobFiles(patterns))
diff --git a/examples/Directory.Build.props b/examples/Directory.Build.props
index 298ab058..8169e2e2 100644
--- a/examples/Directory.Build.props
+++ b/examples/Directory.Build.props
@@ -2,8 +2,8 @@
- $(MSBuildProjectName.Replace('.2010', ''))
-
+ $(MSBuildProjectName.Replace('.2010', ''))
+
$(CleanedProjectName)$(CleanedProjectName)Spring
diff --git a/src/Spring/Spring.Aop/Aop/Config/AopNamespaceParser.cs b/src/Spring/Spring.Aop/Aop/Config/AopNamespaceParser.cs
index d75f05e7..5fd5d311 100644
--- a/src/Spring/Spring.Aop/Aop/Config/AopNamespaceParser.cs
+++ b/src/Spring/Spring.Aop/Aop/Config/AopNamespaceParser.cs
@@ -20,35 +20,34 @@
using Spring.Objects.Factory.Xml;
-namespace Spring.Aop.Config
+namespace Spring.Aop.Config;
+
+///
+/// Namespace parser for the aop namespace.
+///
+///
+/// Using the advisor tag you can configure an and have it
+/// applied to all the relevant objects in your application context automatically. The
+/// advisor tag supports only referenced s.
+///
+/// Rob harrop
+/// Adrian Colyer
+/// Rod Johnson
+/// Mark Pollack (.NET)
+[
+ NamespaceParser(
+ Namespace = "http://www.springframework.net/aop",
+ SchemaLocationAssemblyHint = typeof(AopNamespaceParser),
+ SchemaLocation = "/Spring.Aop.Config/spring-aop-1.1.xsd"
+ )
+]
+public class AopNamespaceParser : NamespaceParserSupport
{
///
- /// Namespace parser for the aop namespace.
+ /// Register the for the 'config' tag.
///
- ///
- /// Using the advisor tag you can configure an and have it
- /// applied to all the relevant objects in your application context automatically. The
- /// advisor tag supports only referenced s.
- ///
- /// Rob harrop
- /// Adrian Colyer
- /// Rod Johnson
- /// Mark Pollack (.NET)
- [
- NamespaceParser(
- Namespace = "http://www.springframework.net/aop",
- SchemaLocationAssemblyHint = typeof (AopNamespaceParser),
- SchemaLocation = "/Spring.Aop.Config/spring-aop-1.1.xsd"
- )
- ]
- public class AopNamespaceParser : NamespaceParserSupport
+ public override void Init()
{
- ///
- /// Register the for the 'config' tag.
- ///
- public override void Init()
- {
- RegisterObjectDefinitionParser("config", new ConfigObjectDefinitionParser());
- }
+ RegisterObjectDefinitionParser("config", new ConfigObjectDefinitionParser());
}
}
\ No newline at end of file
diff --git a/src/Spring/Spring.Aop/Aop/Config/AopNamespaceUtils.cs b/src/Spring/Spring.Aop/Aop/Config/AopNamespaceUtils.cs
index 9bb596c0..e96ccd6f 100644
--- a/src/Spring/Spring.Aop/Aop/Config/AopNamespaceUtils.cs
+++ b/src/Spring/Spring.Aop/Aop/Config/AopNamespaceUtils.cs
@@ -29,67 +29,66 @@ using Spring.Util;
#endregion
-namespace Spring.Aop.Config
+namespace Spring.Aop.Config;
+
+///
+/// Utility class for handling registration of auto-proxy creators used internally by the
+/// aop and tx namespace tags.
+///
+/// Rob Harrop
+/// Juergen Hoeller
+/// Mark Pollack (.NET)
+/// Erich Eichinger (.NET)
+public class AopNamespaceUtils
{
///
- /// Utility class for handling registration of auto-proxy creators used internally by the
- /// aop and tx namespace tags.
+ /// The object name of the internally managed auto-proxy creator.
///
- /// Rob Harrop
- /// Juergen Hoeller
- /// Mark Pollack (.NET)
- /// Erich Eichinger (.NET)
- public class AopNamespaceUtils
+ public static readonly string AUTO_PROXY_CREATOR_OBJECT_NAME = "Spring.Aop.Config.InternalAutoProxyCreator";
+
+ ///
+ /// The type of the APC that handles advisors with object role .
+ ///
+ private static readonly Type InfrastructureAutoProxyCreatorType = typeof(InfrastructureAdvisorAutoProxyCreator);
+
+ ///
+ /// Registers the internal auto proxy creator if necessary.
+ ///
+ /// The parser context.
+ /// The source element.
+ public static void RegisterAutoProxyCreatorIfNecessary(ParserContext parserContext, XmlElement sourceElement)
{
- ///
- /// The object name of the internally managed auto-proxy creator.
- ///
- public static readonly string AUTO_PROXY_CREATOR_OBJECT_NAME = "Spring.Aop.Config.InternalAutoProxyCreator";
+ AssertUtils.ArgumentNotNull(parserContext, "parserContext");
+ IObjectDefinitionRegistry registry = parserContext.Registry;
+ RegisterAutoProxyCreatorIfNecessary(registry);
+ }
- ///
- /// The type of the APC that handles advisors with object role .
- ///
- private static readonly Type InfrastructureAutoProxyCreatorType = typeof(InfrastructureAdvisorAutoProxyCreator);
+ ///
+ /// Registers the internal auto proxy creator if necessary.
+ ///
+ public static void RegisterAutoProxyCreatorIfNecessary(IObjectDefinitionRegistry registry)
+ {
+ AssertUtils.ArgumentNotNull(registry, "registry");
- ///
- /// Registers the internal auto proxy creator if necessary.
- ///
- /// The parser context.
- /// The source element.
- public static void RegisterAutoProxyCreatorIfNecessary(ParserContext parserContext, XmlElement sourceElement)
+ if (!registry.ContainsObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME))
{
- AssertUtils.ArgumentNotNull(parserContext, "parserContext");
- IObjectDefinitionRegistry registry = parserContext.Registry;
- RegisterAutoProxyCreatorIfNecessary(registry);
+ RootObjectDefinition objectDefinition = new RootObjectDefinition(InfrastructureAutoProxyCreatorType);
+ objectDefinition.Role = ObjectRole.ROLE_INFRASTRUCTURE;
+ objectDefinition.PropertyValues.Add("order", int.MaxValue);
+ registry.RegisterObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME, objectDefinition);
}
+ }
- ///
- /// Registers the internal auto proxy creator if necessary.
- ///
- public static void RegisterAutoProxyCreatorIfNecessary(IObjectDefinitionRegistry registry)
+ ///
+ /// Forces the auto proxy creator to use decorator proxy.
+ ///
+ /// The registry.
+ public static void ForceAutoProxyCreatorToUseDecoratorProxy(IObjectDefinitionRegistry registry)
+ {
+ if (registry.ContainsObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME))
{
- AssertUtils.ArgumentNotNull(registry, "registry");
-
- if (!registry.ContainsObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME))
- {
- RootObjectDefinition objectDefinition = new RootObjectDefinition(InfrastructureAutoProxyCreatorType);
- objectDefinition.Role = ObjectRole.ROLE_INFRASTRUCTURE;
- objectDefinition.PropertyValues.Add("order", int.MaxValue);
- registry.RegisterObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME, objectDefinition);
- }
- }
-
- ///
- /// Forces the auto proxy creator to use decorator proxy.
- ///
- /// The registry.
- public static void ForceAutoProxyCreatorToUseDecoratorProxy(IObjectDefinitionRegistry registry)
- {
- if (registry.ContainsObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME))
- {
- IObjectDefinition definition = registry.GetObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME);
- definition.PropertyValues.Add("ProxyTargetType", true);
- }
+ IObjectDefinition definition = registry.GetObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME);
+ definition.PropertyValues.Add("ProxyTargetType", true);
}
}
}
diff --git a/src/Spring/Spring.Aop/Aop/Config/ConfigObjectDefinitionParser.cs b/src/Spring/Spring.Aop/Aop/Config/ConfigObjectDefinitionParser.cs
index 7366d35b..d092ae04 100644
--- a/src/Spring/Spring.Aop/Aop/Config/ConfigObjectDefinitionParser.cs
+++ b/src/Spring/Spring.Aop/Aop/Config/ConfigObjectDefinitionParser.cs
@@ -18,7 +18,6 @@
#endregion
-
using System.Xml;
using Spring.Aop.Support;
using Spring.Objects.Factory.Config;
@@ -26,134 +25,129 @@ using Spring.Objects.Factory.Support;
using Spring.Objects.Factory.Xml;
using Spring.Util;
-namespace Spring.Aop.Config
+namespace Spring.Aop.Config;
+
+///
+/// The for the <aop:config> tag.
+///
+/// Mark Pollack (.NET)
+public class ConfigObjectDefinitionParser : IObjectDefinitionParser
{
///
- /// The for the <aop:config> tag.
+ /// The 'proxy-target-type' attribute
///
- /// Mark Pollack (.NET)
- public class ConfigObjectDefinitionParser : IObjectDefinitionParser
+ private static readonly string PROXY_TARGET_TYPE = "proxy-target-type";
+
+ private static readonly string ID = "id";
+
+ private static readonly string ORDER_PROPERTY = "order";
+
+ private static readonly string ADVICE_REF = "advice-ref";
+
+ private static readonly string ADVICE_OBJECT_NAME = "adviceObjectName";
+
+ private static readonly string POINTCUT_REF = "pointcut-ref";
+
+ #region IObjectDefinitionParser Members
+
+ ///
+ /// Parse the specified XmlElement and register the resulting
+ /// ObjectDefinitions with the IObjectDefinitionRegistry
+ /// embedded in the supplied
+ ///
+ /// The element to be parsed.
+ /// The object encapsulating the current state of the parsing process.
+ /// Provides access to a IObjectDefinitionRegistry
+ /// The primary object definition.
+ ///
+ ///
+ /// This method is never invoked if the parser is namespace aware
+ /// and was called to process the root node.
+ ///
+ ///
+ public IObjectDefinition ParseElement(XmlElement element, ParserContext parserContext)
{
- ///
- /// The 'proxy-target-type' attribute
- ///
- private static readonly string PROXY_TARGET_TYPE = "proxy-target-type";
+ ConfigureAutoProxyCreator(parserContext, element);
+ XmlNodeList advisorNodes = element.GetElementsByTagName("advisor", element.NamespaceURI);
- private static readonly string ID = "id";
-
- private static readonly string ORDER_PROPERTY = "order";
-
- private static readonly string ADVICE_REF = "advice-ref";
-
- private static readonly string ADVICE_OBJECT_NAME = "adviceObjectName";
-
- private static readonly string POINTCUT_REF = "pointcut-ref";
-
-
- #region IObjectDefinitionParser Members
-
- ///
- /// Parse the specified XmlElement and register the resulting
- /// ObjectDefinitions with the IObjectDefinitionRegistry
- /// embedded in the supplied
- ///
- /// The element to be parsed.
- /// The object encapsulating the current state of the parsing process.
- /// Provides access to a IObjectDefinitionRegistry
- /// The primary object definition.
- ///
- ///
- /// This method is never invoked if the parser is namespace aware
- /// and was called to process the root node.
- ///
+/// Subclasses can override the
+///
+/// method to change this behavior, so this is a useful/ base class for
+/// implementations.
+///
+///
+/// Rod Johnson
+/// Aleksandar Seovic (.NET)
+/// Rick Evans (.NET)
+/// Bruno Baia (.NET)
+[Serializable]
+public abstract class AbstractMethodInvocation : IMethodInvocation
{
- ///
- /// Convenience base class for
- /// implementations.
- ///
- ///
- ///
- /// Subclasses can override the
- ///
- /// method to change this behavior, so this is a useful/ base class for
- /// implementations.
- ///
- ///
- /// Rod Johnson
- /// Aleksandar Seovic (.NET)
- /// Rick Evans (.NET)
- /// Bruno Baia (.NET)
- [Serializable]
- public abstract class AbstractMethodInvocation : IMethodInvocation
- {
- ///
- /// The arguments (if any = may be ) to the method
- /// that is to be invoked.
- ///
- private object[] arguments;
+ ///
+ /// The arguments (if any = may be ) to the method
+ /// that is to be invoked.
+ ///
+ private object[] arguments;
- ///
- /// The target object that the method is to be invoked on.
- ///
- private readonly object target;
+ ///
+ /// The target object that the method is to be invoked on.
+ ///
+ private readonly object target;
- ///
- /// The AOP proxy for the target object.
- ///
- private object proxy;
+ ///
+ /// The AOP proxy for the target object.
+ ///
+ private object proxy;
- ///
- /// The method invocation that is to be invoked.
- ///
- private MethodInfo method;
+ ///
+ /// The method invocation that is to be invoked.
+ ///
+ private MethodInfo method;
- ///
- /// The list of and
- ///
- /// that need dynamic checks.
- ///
- private IList interceptors;
+ ///
+ /// The list of and
+ ///
+ /// that need dynamic checks.
+ ///
+ private IList interceptors;
- ///
- /// The declaring type of the method that is to be invoked.
- ///
- private Type targetType;
+ ///
+ /// The declaring type of the method that is to be invoked.
+ ///
+ private Type targetType;
- ///
- /// The index from 0 of the current interceptor we're invoking.
- ///
- private int currentInterceptorIndex;
+ ///
+ /// The index from 0 of the current interceptor we're invoking.
+ ///
+ private int currentInterceptorIndex;
- ///
- /// Creates a new instance of the
- /// class.
- ///
- ///
- ///
- /// This is an abstract class, and as such exposes no publicly visible
- /// constructors.
- ///
- ///
- ///
- /// The list can also contain any
- /// s
- /// that need evaluation at runtime.
- /// s included in an
- ///
- /// must already have been found to have matched as far as was possible
- /// statically. Passing an array might be about 10% faster, but
- /// would complicate the code, and it would work only for static
- /// pointcuts.
- ///
- ///
- ///
- /// The AOP proxy.
- /// The target object.
- /// the target method.
- /// The target method's arguments.
- ///
- /// The of the target object.
- ///
- /// The list of interceptors that are to be applied. May be
- /// .
- ///
- ///
- /// If the is .
- ///
- protected AbstractMethodInvocation(object proxy, object target,
- MethodInfo method, object[] arguments, Type targetType, IList interceptors)
- {
- // EE: There is not necessarily always a target - e.g. for DynamicEntities
- // moved this check to InvokeJoinpoint()
- AssertUtils.ArgumentNotNull(method, "method");
+ ///
+ /// Creates a new instance of the
+ /// class.
+ ///
+ ///
+ ///
+ /// This is an abstract class, and as such exposes no publicly visible
+ /// constructors.
+ ///
+ ///
+ ///
+ /// The list can also contain any
+ /// s
+ /// that need evaluation at runtime.
+ /// s included in an
+ ///
+ /// must already have been found to have matched as far as was possible
+ /// statically. Passing an array might be about 10% faster, but
+ /// would complicate the code, and it would work only for static
+ /// pointcuts.
+ ///
+ ///
+ ///
+ /// The AOP proxy.
+ /// The target object.
+ /// the target method.
+ /// The target method's arguments.
+ ///
+ /// The of the target object.
+ ///
+ /// The list of interceptors that are to be applied. May be
+ /// .
+ ///
+ ///
+ /// If the is .
+ ///
+ protected AbstractMethodInvocation(object proxy, object target,
+ MethodInfo method, object[] arguments, Type targetType, IList interceptors)
+ {
+ // EE: There is not necessarily always a target - e.g. for DynamicEntities
+ // moved this check to InvokeJoinpoint()
+ AssertUtils.ArgumentNotNull(method, "method");
- this.proxy = proxy;
- this.target = target;
- this.method = method;
- this.targetType = targetType;
- this.arguments = arguments;
- this.interceptors = interceptors;
- }
+ this.proxy = proxy;
+ this.target = target;
+ this.method = method;
+ this.targetType = targetType;
+ this.arguments = arguments;
+ this.interceptors = interceptors;
+ }
- ///
- /// Gets the method invocation that is to be invoked.
- ///
- ///
- ///
- /// May or may not correspond with a method invoked on an underlying
- /// implementation of that interface.
- ///
- ///
- ///
- public virtual MethodInfo Method
- {
- get { return method; }
- protected set { method = value; }
- }
+ ///
+ /// Gets the method invocation that is to be invoked.
+ ///
+ ///
+ ///
+ /// May or may not correspond with a method invoked on an underlying
+ /// implementation of that interface.
+ ///
+ ///
+ ///
+ public virtual MethodInfo Method
+ {
+ get { return method; }
+ protected set { method = value; }
+ }
- ///
- /// Gets the static part of this joinpoint.
- ///
- ///
- /// The proxied member's information.
- ///
- ///
- public virtual MemberInfo StaticPart
- {
- get { return Method; }
- }
+ ///
+ /// Gets the static part of this joinpoint.
+ ///
+ ///
+ /// The proxied member's information.
+ ///
+ ///
+ public virtual MemberInfo StaticPart
+ {
+ get { return Method; }
+ }
- ///
- /// Gets the proxy that this interception was made through.
- ///
- ///
- /// The proxy that this interception was made through.
- ///
- public virtual object Proxy
- {
- get { return this.proxy; }
- protected set { this.proxy = value; }
- }
- ///
- /// Gets the target object for the invocation.
- ///
- ///
- /// The target object for this method invocation.
- ///
- public virtual object Target
- {
- get { return this.target; }
- }
- ///
- /// Gets the type of the target object.
- ///
- ///
- /// The type of the target object.
- ///
- public virtual Type TargetType
- {
- get { return this.targetType; }
- protected set { this.targetType = value; }
- }
+ ///
+ /// Gets the proxy that this interception was made through.
+ ///
+ ///
+ /// The proxy that this interception was made through.
+ ///
+ public virtual object Proxy
+ {
+ get { return this.proxy; }
+ protected set { this.proxy = value; }
+ }
- ///
- /// Gets and sets the arguments (if any - may be )
- /// to the method that is to be invoked.
- ///
- ///
- /// The arguments (if any - may be ) to the
- /// method that is to be invoked.
- ///
- ///
- public virtual object[] Arguments
- {
- get { return this.arguments; }
- set { this.arguments = value; }
- }
+ ///
+ /// Gets the target object for the invocation.
+ ///
+ ///
+ /// The target object for this method invocation.
+ ///
+ public virtual object Target
+ {
+ get { return this.target; }
+ }
- ///
- /// The list of method interceptors.
- ///
- ///
- ///
- /// May be .
- ///
- ///
- public virtual IList Interceptors
- {
- get { return this.interceptors; }
- set { this.interceptors = value; }
- }
+ ///
+ /// Gets the type of the target object.
+ ///
+ ///
+ /// The type of the target object.
+ ///
+ public virtual Type TargetType
+ {
+ get { return this.targetType; }
+ protected set { this.targetType = value; }
+ }
- ///
- /// Gets the target object.
- ///
- public virtual object This
- {
- get { return this.target; }
- }
+ ///
+ /// Gets and sets the arguments (if any - may be )
+ /// to the method that is to be invoked.
+ ///
+ ///
+ /// The arguments (if any - may be ) to the
+ /// method that is to be invoked.
+ ///
+ ///
+ public virtual object[] Arguments
+ {
+ get { return this.arguments; }
+ set { this.arguments = value; }
+ }
- ///
- /// The index from 0 of the current interceptor we're invoking.
- ///
- protected int CurrentInterceptorIndex
- {
- get { return currentInterceptorIndex; }
- set { currentInterceptorIndex = value; }
- }
+ ///
+ /// The list of method interceptors.
+ ///
+ ///
+ ///
+ /// May be .
+ ///
+ ///
+ public virtual IList Interceptors
+ {
+ get { return this.interceptors; }
+ set { this.interceptors = value; }
+ }
- ///
- /// Proceeds to the next interceptor in the chain.
- ///
- ///
- /// The return value of the method invocation.
- ///
- ///
- /// If any of the interceptors at the joinpoint throws an exception.
- ///
- ///
- public virtual object Proceed()
- {
- if (this.interceptors == null ||
- this.currentInterceptorIndex == this.interceptors.Count)
- {
- AssertJoinpoint();
- return InvokeJoinpoint();
- }
- object interceptor = this.interceptors[this.currentInterceptorIndex];
- InterceptorAndDynamicMethodMatcher dynamicMatcher
- = interceptor as InterceptorAndDynamicMethodMatcher;
- IMethodInvocation nextInvocation = PrepareMethodInvocationForProceed(this);
- if (dynamicMatcher != null)
- {
- // evaluate dynamic method matcher here: static part will already have
- // been evaluated and found to match...
- if (dynamicMatcher.MethodMatcher.Matches(
+ ///
+ /// Gets the target object.
+ ///
+ public virtual object This
+ {
+ get { return this.target; }
+ }
+
+ ///
+ /// The index from 0 of the current interceptor we're invoking.
+ ///
+ protected int CurrentInterceptorIndex
+ {
+ get { return currentInterceptorIndex; }
+ set { currentInterceptorIndex = value; }
+ }
+
+ ///
+ /// Proceeds to the next interceptor in the chain.
+ ///
+ ///
+ /// The return value of the method invocation.
+ ///
+ ///
+ /// If any of the interceptors at the joinpoint throws an exception.
+ ///
+ ///
+ public virtual object Proceed()
+ {
+ if (this.interceptors == null ||
+ this.currentInterceptorIndex == this.interceptors.Count)
+ {
+ AssertJoinpoint();
+ return InvokeJoinpoint();
+ }
+
+ object interceptor = this.interceptors[this.currentInterceptorIndex];
+ InterceptorAndDynamicMethodMatcher dynamicMatcher
+ = interceptor as InterceptorAndDynamicMethodMatcher;
+ IMethodInvocation nextInvocation = PrepareMethodInvocationForProceed(this);
+ if (dynamicMatcher != null)
+ {
+ // evaluate dynamic method matcher here: static part will already have
+ // been evaluated and found to match...
+ if (dynamicMatcher.MethodMatcher.Matches(
nextInvocation.Method, nextInvocation.TargetType, nextInvocation.Arguments))
- {
- return dynamicMatcher.Interceptor.Invoke(nextInvocation);
- }
- else
- {
- // dynamic match failed; skip this interceptor and invoke the next in the chain...
- return nextInvocation.Proceed();
- }
+ {
+ return dynamicMatcher.Interceptor.Invoke(nextInvocation);
}
else
{
- // it's an interceptor so we just invoke it: the pointcut will have
- // been evaluated statically before this object was constructed...
- return ((IMethodInterceptor)interceptor).Invoke(nextInvocation);
+ // dynamic match failed; skip this interceptor and invoke the next in the chain...
+ return nextInvocation.Proceed();
}
- }
-
- ///
- /// Retrieves a new instance
- /// for the next Proceed method call.
- ///
- ///
- /// The current instance.
- ///
- ///
- /// The new instance to use.
- ///
- ///
- protected abstract IMethodInvocation PrepareMethodInvocationForProceed(
- IMethodInvocation invocation);
-
- ///
- /// Performs sanity checks, whether the actual joinpoint may be invoked
- ///
- ///
- /// By default checks that the underlying target is not null and the called method is implemented
- /// by the target's type.
- ///
- /// if is null.
- /// if the 's type does not implement .
- protected virtual void AssertJoinpoint()
+ }
+ else
{
- AssertUtils.ArgumentNotNull(target, "target");
+ // it's an interceptor so we just invoke it: the pointcut will have
+ // been evaluated statically before this object was constructed...
+ return ((IMethodInterceptor) interceptor).Invoke(nextInvocation);
+ }
+ }
+
+ ///
+ /// Retrieves a new instance
+ /// for the next Proceed method call.
+ ///
+ ///
+ /// The current instance.
+ ///
+ ///
+ /// The new instance to use.
+ ///
+ ///
+ protected abstract IMethodInvocation PrepareMethodInvocationForProceed(
+ IMethodInvocation invocation);
+
+ ///
+ /// Performs sanity checks, whether the actual joinpoint may be invoked
+ ///
+ ///
+ /// By default checks that the underlying target is not null and the called method is implemented
+ /// by the target's type.
+ ///
+ /// if is null.
+ /// if the 's type does not implement .
+ protected virtual void AssertJoinpoint()
+ {
+ AssertUtils.ArgumentNotNull(target, "target");
// if (this.method != null
// && !this.method.DeclaringType.IsAssignableFrom(target.GetType()))
// {
@@ -324,56 +326,56 @@ namespace Spring.Aop.Framework
// // Since no interceptor has handled the call, we throw a sensible exception here.
// throw new NotSupportedException(string.Format("Interface method '{0}.{1}()' was not handled by any interceptor and the underlying target type '{2}' does not implement this method.", method.DeclaringType.FullName, method.Name, target.GetType().FullName));
// }
+ }
+
+ ///
+ /// Invokes the joinpoint.
+ ///
+ ///
+ ///
+ /// Subclasses can override this to use custom invocation.
+ ///
+ ///
+ ///
+ /// The return value of the invocation of the joinpoint.
+ ///
+ ///
+ /// If invoking the joinpoint resulted in an exception.
+ ///
+ ///
+ protected abstract object InvokeJoinpoint();
+
+ ///
+ /// A that represents the current
+ /// invocation.
+ ///
+ ///
+ ///
+ ///
+ /// Does not invoke on the
+ /// target
+ /// object, as that too may be proxied.
+ ///
+ ///
+ ///
+ ///
+ /// A that represents the current invocation.
+ ///
+ public override string ToString()
+ {
+ StringBuilder buffer = new StringBuilder("Invocation: method '");
+ buffer.Append(Method.Name).Append("', ").Append("arguments ");
+ buffer.Append(Arguments != null ? StringUtils.CollectionToCommaDelimitedString(Arguments) : "[none]");
+ buffer.Append("; ");
+ if (Target == null)
+ {
+ buffer.Append("target is null.");
+ }
+ else
+ {
+ buffer.Append("target is of Type [").Append(TargetType.FullName).Append(']');
}
- ///
- /// Invokes the joinpoint.
- ///
- ///
- ///
- /// Subclasses can override this to use custom invocation.
- ///
- ///
- ///
- /// The return value of the invocation of the joinpoint.
- ///
- ///
- /// If invoking the joinpoint resulted in an exception.
- ///
- ///
- protected abstract object InvokeJoinpoint();
-
- ///
- /// A that represents the current
- /// invocation.
- ///
- ///
- ///
- ///
- /// Does not invoke on the
- /// target
- /// object, as that too may be proxied.
- ///
- ///
- ///
- ///
- /// A that represents the current invocation.
- ///
- public override string ToString()
- {
- StringBuilder buffer = new StringBuilder("Invocation: method '");
- buffer.Append(Method.Name).Append("', ").Append("arguments ");
- buffer.Append(Arguments != null ? StringUtils.CollectionToCommaDelimitedString(Arguments) : "[none]");
- buffer.Append("; ");
- if (Target == null)
- {
- buffer.Append("target is null.");
- }
- else
- {
- buffer.Append("target is of Type [").Append(TargetType.FullName).Append(']');
- }
- return buffer.ToString();
- }
- }
+ return buffer.ToString();
+ }
}
diff --git a/src/Spring/Spring.Aop/Aop/Framework/Adapter/AdvisorAdapterRegistrationManager.cs b/src/Spring/Spring.Aop/Aop/Framework/Adapter/AdvisorAdapterRegistrationManager.cs
index b68b51ed..6942e57e 100644
--- a/src/Spring/Spring.Aop/Aop/Framework/Adapter/AdvisorAdapterRegistrationManager.cs
+++ b/src/Spring/Spring.Aop/Aop/Framework/Adapter/AdvisorAdapterRegistrationManager.cs
@@ -24,85 +24,85 @@ using Spring.Objects.Factory.Config;
#endregion
-namespace Spring.Aop.Framework.Adapter
+namespace Spring.Aop.Framework.Adapter;
+
+///
+/// implementation
+/// that registers instances of any non-default
+/// instances with the
+///
+/// singleton.
+///
+///
+///
+/// The only requirement for it to work is that it needs to be defined
+/// in an application context along with any arbitrary "non-native" Spring.NET
+/// instances that need
+/// to be recognized by Spring.NET's AOP framework.
+///
+///
+/// Dmitriy Kopylenko
+/// Aleksandar Seovic (.NET)
+public class AdvisorAdapterRegistrationManager : IObjectPostProcessor
{
///
- /// implementation
- /// that registers instances of any non-default
- /// instances with the
- ///
- /// singleton.
+ /// Apply this
+ /// to the given new object instance before any object initialization callbacks.
///
///
///
- /// The only requirement for it to work is that it needs to be defined
- /// in an application context along with any arbitrary "non-native" Spring.NET
- /// instances that need
- /// to be recognized by Spring.NET's AOP framework.
+ /// Does nothing, simply returns the supplied as is.
///
///
- /// Dmitriy Kopylenko
- /// Aleksandar Seovic (.NET)
- public class AdvisorAdapterRegistrationManager : IObjectPostProcessor
+ ///
+ /// The new object instance.
+ ///
+ ///
+ /// The name of the object.
+ ///
+ ///
+ /// The object instance to use, either the original or a wrapped one.
+ ///
+ ///
+ /// In case of errors.
+ ///
+ public virtual object PostProcessBeforeInitialization(object instance, string name)
{
- ///
- /// Apply this
- /// to the given new object instance before any object initialization callbacks.
- ///
- ///
- ///
- /// Does nothing, simply returns the supplied as is.
- ///
- ///
- ///
- /// The new object instance.
- ///
- ///
- /// The name of the object.
- ///
- ///
- /// The object instance to use, either the original or a wrapped one.
- ///
- ///
- /// In case of errors.
- ///
- public virtual object PostProcessBeforeInitialization(object instance, string name)
+ return instance;
+ }
+
+ ///
+ /// Apply this to the
+ /// given new object instance after any object initialization callbacks.
+ ///
+ ///
+ ///
+ /// Registers the supplied with the
+ ///
+ /// singleton if it is an
+ /// instance.
+ ///
+ ///
+ ///
+ /// The new object instance.
+ ///
+ ///
+ /// The name of the object.
+ ///
+ ///
+ /// The object instance to use, either the original or a wrapped one.
+ ///
+ ///
+ /// In case of errors.
+ ///
+ public virtual object PostProcessAfterInitialization(object instance, string objectName)
+ {
+ IAdvisorAdapter adapter = instance as IAdvisorAdapter;
+ if (adapter != null)
{
- return instance;
+ GlobalAdvisorAdapterRegistry.Instance.RegisterAdvisorAdapter(adapter);
}
- ///
- /// Apply this to the
- /// given new object instance after any object initialization callbacks.
- ///
- ///
- ///
- /// Registers the supplied with the
- ///
- /// singleton if it is an
- /// instance.
- ///
- ///
- ///
- /// The new object instance.
- ///
- ///
- /// The name of the object.
- ///
- ///
- /// The object instance to use, either the original or a wrapped one.
- ///
- ///
- /// In case of errors.
- ///
- public virtual object PostProcessAfterInitialization(object instance, string objectName)
- {
- IAdvisorAdapter adapter = instance as IAdvisorAdapter;
- if (adapter != null)
- {
- GlobalAdvisorAdapterRegistry.Instance.RegisterAdvisorAdapter(adapter);
- }
- return instance;
- }
+ return instance;
}
-}
\ No newline at end of file
+}
diff --git a/src/Spring/Spring.Aop/Aop/Framework/Adapter/AfterReturningAdviceAdapter.cs b/src/Spring/Spring.Aop/Aop/Framework/Adapter/AfterReturningAdviceAdapter.cs
index f9d0ef0f..afa91d1e 100644
--- a/src/Spring/Spring.Aop/Aop/Framework/Adapter/AfterReturningAdviceAdapter.cs
+++ b/src/Spring/Spring.Aop/Aop/Framework/Adapter/AfterReturningAdviceAdapter.cs
@@ -25,55 +25,54 @@ using AopAlliance.Intercept;
#endregion
-namespace Spring.Aop.Framework.Adapter
+namespace Spring.Aop.Framework.Adapter;
+
+///
+/// implementation
+/// to enable to be used in the
+/// Spring.NET AOP framework.
+///
+/// Rod Johnson
+/// Aleksandar Seovic (.NET)
+[Serializable]
+internal class AfterReturningAdviceAdapter : IAdvisorAdapter
{
///
- /// implementation
- /// to enable to be used in the
- /// Spring.NET AOP framework.
+ /// Returns if the supplied
+ /// is an instance of the
+ /// interface.
///
- /// Rod Johnson
- /// Aleksandar Seovic (.NET)
- [Serializable]
- internal class AfterReturningAdviceAdapter : IAdvisorAdapter
+ /// The advice to check.
+ ///
+ /// if the supplied is
+ /// an instance of the interface;
+ /// if not or if the supplied
+ /// is .
+ ///
+ public virtual bool SupportsAdvice(IAdvice advice)
{
- ///
- /// Returns if the supplied
- /// is an instance of the
- /// interface.
- ///
- /// The advice to check.
- ///
- /// if the supplied is
- /// an instance of the interface;
- /// if not or if the supplied
- /// is .
- ///
- public virtual bool SupportsAdvice(IAdvice advice)
- {
- return advice is IAfterReturningAdvice;
- }
+ return advice is IAfterReturningAdvice;
+ }
- ///
- /// Wraps the supplied 's
- /// within a
- ///
- /// instance.
- ///
- ///
- /// The advisor exposing the that
- /// is to be wrapped.
- ///
- ///
- /// The supplied 's
- /// wrapped within a
- ///
- /// instance.
- ///
- public virtual IInterceptor GetInterceptor(IAdvisor advisor)
- {
- IAfterReturningAdvice advice = (IAfterReturningAdvice) advisor.Advice;
- return new AfterReturningAdviceInterceptor(advice);
- }
+ ///
+ /// Wraps the supplied 's
+ /// within a
+ ///
+ /// instance.
+ ///
+ ///
+ /// The advisor exposing the that
+ /// is to be wrapped.
+ ///
+ ///
+ /// The supplied 's
+ /// wrapped within a
+ ///
+ /// instance.
+ ///
+ public virtual IInterceptor GetInterceptor(IAdvisor advisor)
+ {
+ IAfterReturningAdvice advice = (IAfterReturningAdvice) advisor.Advice;
+ return new AfterReturningAdviceInterceptor(advice);
}
}
diff --git a/src/Spring/Spring.Aop/Aop/Framework/Adapter/AfterReturningAdviceInterceptor.cs b/src/Spring/Spring.Aop/Aop/Framework/Adapter/AfterReturningAdviceInterceptor.cs
index 4eaa8a96..2fde088f 100644
--- a/src/Spring/Spring.Aop/Aop/Framework/Adapter/AfterReturningAdviceInterceptor.cs
+++ b/src/Spring/Spring.Aop/Aop/Framework/Adapter/AfterReturningAdviceInterceptor.cs
@@ -25,71 +25,70 @@ using Spring.Util;
#endregion
-namespace Spring.Aop.Framework.Adapter
+namespace Spring.Aop.Framework.Adapter;
+
+///
+/// Interceptor to wrap an
+/// instance.
+///
+///
+///
+/// A more efficient alternative solution in cases where there is no
+/// interception advice and therefore no need to create an
+/// object may be
+/// offered in future.
+///
+///
+/// Used internally by the AOP framework: application developers should not need
+/// to use this class directly.
+///
+///
+/// Rod Johnson
+/// Aleksandar Seovic (.NET)
+[Serializable]
+public sealed class AfterReturningAdviceInterceptor : IMethodInterceptor
{
- ///
- /// Interceptor to wrap an
- /// instance.
- ///
- ///
- ///
- /// A more efficient alternative solution in cases where there is no
- /// interception advice and therefore no need to create an
- /// object may be
- /// offered in future.
- ///
- ///
- /// Used internally by the AOP framework: application developers should not need
- /// to use this class directly.
- ///
- ///
- /// Rod Johnson
- /// Aleksandar Seovic (.NET)
- [Serializable]
- public sealed class AfterReturningAdviceInterceptor : IMethodInterceptor
- {
- private IAfterReturningAdvice advice;
+ private IAfterReturningAdvice advice;
- ///
- /// Creates a new instance of the
- ///
- /// class.
- ///
- ///
- /// The advice to be applied after a target method successfully
- /// returns.
- ///
- ///
- /// If the supplied is .
- ///
- public AfterReturningAdviceInterceptor(IAfterReturningAdvice advice)
- {
- AssertUtils.ArgumentNotNull(advice, "advice");
- this.advice = advice;
- }
+ ///
+ /// Creates a new instance of the
+ ///
+ /// class.
+ ///
+ ///
+ /// The advice to be applied after a target method successfully
+ /// returns.
+ ///
+ ///
+ /// If the supplied is .
+ ///
+ public AfterReturningAdviceInterceptor(IAfterReturningAdvice advice)
+ {
+ AssertUtils.ArgumentNotNull(advice, "advice");
+ this.advice = advice;
+ }
- ///
- /// Executes interceptor after the target method successfully returns.
- ///
- ///
- /// The method invocation that is being intercepted.
- ///
- ///
- /// The result of the call to the
- /// method of
- /// the supplied ; this return value may
- /// well have been intercepted by the interceptor.
- ///
- ///
- /// If any of the interceptors in the chain or the target object itself
- /// throws an exception.
- ///
- public object Invoke(IMethodInvocation invocation)
- {
- object returnValue = invocation.Proceed();
- advice.AfterReturning(
- returnValue, invocation.Method, invocation.Arguments, invocation.This);
- return returnValue;
- }
- }
+ ///
+ /// Executes interceptor after the target method successfully returns.
+ ///
+ ///
+ /// The method invocation that is being intercepted.
+ ///
+ ///
+ /// The result of the call to the
+ /// method of
+ /// the supplied ; this return value may
+ /// well have been intercepted by the interceptor.
+ ///
+ ///
+ /// If any of the interceptors in the chain or the target object itself
+ /// throws an exception.
+ ///
+ public object Invoke(IMethodInvocation invocation)
+ {
+ object returnValue = invocation.Proceed();
+ advice.AfterReturning(
+ returnValue, invocation.Method, invocation.Arguments, invocation.This);
+ return returnValue;
+ }
}
diff --git a/src/Spring/Spring.Aop/Aop/Framework/Adapter/BeforeAdviceAdapter.cs b/src/Spring/Spring.Aop/Aop/Framework/Adapter/BeforeAdviceAdapter.cs
index bafefeaf..bce90c60 100644
--- a/src/Spring/Spring.Aop/Aop/Framework/Adapter/BeforeAdviceAdapter.cs
+++ b/src/Spring/Spring.Aop/Aop/Framework/Adapter/BeforeAdviceAdapter.cs
@@ -25,55 +25,54 @@ using AopAlliance.Intercept;
#endregion
-namespace Spring.Aop.Framework.Adapter
+namespace Spring.Aop.Framework.Adapter;
+
+///
+/// implementation
+/// to enable to be used in the
+/// Spring.NET AOP framework.
+///
+/// Rod Johnson
+/// Aleksandar Seovic (.NET)
+[Serializable]
+internal class BeforeAdviceAdapter : IAdvisorAdapter
{
///
- /// implementation
- /// to enable to be used in the
- /// Spring.NET AOP framework.
+ /// Returns if the supplied
+ /// is an instance of the
+ /// interface.
///
- /// Rod Johnson
- /// Aleksandar Seovic (.NET)
- [Serializable]
- internal class BeforeAdviceAdapter : IAdvisorAdapter
+ /// The advice to check.
+ ///
+ /// if the supplied is
+ /// an instance of the interface;
+ /// if not or if the supplied
+ /// is .
+ ///
+ public virtual bool SupportsAdvice(IAdvice advice)
{
- ///
- /// Returns if the supplied
- /// is an instance of the
- /// interface.
- ///
- /// The advice to check.
- ///
- /// if the supplied is
- /// an instance of the interface;
- /// if not or if the supplied
- /// is .
- ///
- public virtual bool SupportsAdvice(IAdvice advice)
- {
- return advice is IMethodBeforeAdvice;
- }
+ return advice is IMethodBeforeAdvice;
+ }
- ///
- /// Wraps the supplied 's
- /// within a
- ///
- /// instance.
- ///
- ///
- /// The advisor exposing the that
- /// is to be wrapped.
- ///
- ///
- /// The supplied 's
- /// wrapped within a
- ///
- /// instance.
- ///
- public virtual IInterceptor GetInterceptor(IAdvisor advisor)
- {
- IMethodBeforeAdvice advice = (IMethodBeforeAdvice) advisor.Advice;
- return new MethodBeforeAdviceInterceptor(advice);
- }
+ ///
+ /// Wraps the supplied 's
+ /// within a
+ ///
+ /// instance.
+ ///
+ ///
+ /// The advisor exposing the that
+ /// is to be wrapped.
+ ///
+ ///
+ /// The supplied 's
+ /// wrapped within a
+ ///
+ /// instance.
+ ///
+ public virtual IInterceptor GetInterceptor(IAdvisor advisor)
+ {
+ IMethodBeforeAdvice advice = (IMethodBeforeAdvice) advisor.Advice;
+ return new MethodBeforeAdviceInterceptor(advice);
}
}
diff --git a/src/Spring/Spring.Aop/Aop/Framework/Adapter/DefaultAdvisorAdapterRegistry.cs b/src/Spring/Spring.Aop/Aop/Framework/Adapter/DefaultAdvisorAdapterRegistry.cs
index 14519368..1c1beba5 100644
--- a/src/Spring/Spring.Aop/Aop/Framework/Adapter/DefaultAdvisorAdapterRegistry.cs
+++ b/src/Spring/Spring.Aop/Aop/Framework/Adapter/DefaultAdvisorAdapterRegistry.cs
@@ -26,126 +26,131 @@ using Spring.Aop.Support;
#endregion
-namespace Spring.Aop.Framework.Adapter
-{
- ///
- /// Default implementation of the
- ///
- /// interface.
- ///
- /// Rod Johnson
- /// Aleksandar Seovic (.NET)
- [Serializable]
- public class DefaultAdvisorAdapterRegistry : IAdvisorAdapterRegistry
- {
- private readonly IList adapters = new List();
+namespace Spring.Aop.Framework.Adapter;
- ///
- /// Creates a new instance of the
- /// class.
- ///
- ///
- ///
- /// This constructor will also register the well-known
- /// types.
- ///
- ///
- ///
- public DefaultAdvisorAdapterRegistry()
+///
+/// Default implementation of the
+///
+/// interface.
+///
+/// Rod Johnson
+/// Aleksandar Seovic (.NET)
+[Serializable]
+public class DefaultAdvisorAdapterRegistry : IAdvisorAdapterRegistry
+{
+ private readonly IList adapters = new List();
+
+ ///
+ /// Creates a new instance of the
+ /// class.
+ ///
+ ///
+ ///
+ /// This constructor will also register the well-known
+ /// types.
+ ///
+ ///
+ ///
+ public DefaultAdvisorAdapterRegistry()
+ {
+ // register well-known adapters...
+ RegisterAdvisorAdapter(new BeforeAdviceAdapter());
+ RegisterAdvisorAdapter(new AfterReturningAdviceAdapter());
+ RegisterAdvisorAdapter(new ThrowsAdviceAdapter());
+ }
+
+ ///
+ /// Returns an wrapping the supplied
+ /// .
+ ///
+ ///
+ /// The object that should be an advice, such as
+ /// or
+ /// .
+ ///
+ ///
+ /// An wrapping the supplied
+ /// . Never returns . If
+ /// the parameter is an
+ /// , it will simply be returned.
+ ///
+ ///
+ /// If no registered
+ /// can wrap
+ /// the supplied .
+ ///
+ public virtual IAdvisor Wrap(object advice)
+ {
+ if (advice is IAdvisor)
{
- // register well-known adapters...
- RegisterAdvisorAdapter(new BeforeAdviceAdapter());
- RegisterAdvisorAdapter(new AfterReturningAdviceAdapter());
- RegisterAdvisorAdapter(new ThrowsAdviceAdapter());
+ return (IAdvisor) advice;
}
- ///
- /// Returns an wrapping the supplied
- /// .
- ///
- ///
- /// The object that should be an advice, such as
- /// or
- /// .
- ///
- ///
- /// An wrapping the supplied
- /// . Never returns . If
- /// the parameter is an
- /// , it will simply be returned.
- ///
- ///
- /// If no registered
- /// can wrap
- /// the supplied .
- ///
- public virtual IAdvisor Wrap(object advice)
- {
- if (advice is IAdvisor)
- {
- return (IAdvisor) advice;
- }
- if (!(advice is IAdvice))
- {
- throw new UnknownAdviceTypeException(advice);
- }
- IAdvice adviceObject = (IAdvice) advice;
- if (adviceObject is IInterceptor)
- {
- // so well-known it doesn't even need an adapter...
- return new DefaultPointcutAdvisor(adviceObject);
- }
- foreach (IAdvisorAdapter adapter in this.adapters)
- {
- // check that it is supported...
- if (adapter.SupportsAdvice(adviceObject))
- {
- return new DefaultPointcutAdvisor(adviceObject);
- }
- }
- throw new UnknownAdviceTypeException(advice);
- }
+ if (!(advice is IAdvice))
+ {
+ throw new UnknownAdviceTypeException(advice);
+ }
- ///
- /// Returns an to
- /// allow the use of the supplied in an
- /// interception-based framework.
- ///
- /// The advisor to find an interceptor for.
- ///
- /// An interceptor to expose this advisor's behaviour.
- ///
- ///
- /// If the advisor type is not understood by any registered
- /// .
- ///
- public virtual IInterceptor GetInterceptor(IAdvisor advisor)
- {
- IAdvice advice = advisor.Advice;
- if (advice is IInterceptor)
- {
- return (IInterceptor) advice;
- }
- foreach (IAdvisorAdapter adapter in this.adapters)
- {
- if (adapter.SupportsAdvice(advice))
- {
- return adapter.GetInterceptor(advisor);
- }
- }
- throw new UnknownAdviceTypeException(advice);
- }
+ IAdvice adviceObject = (IAdvice) advice;
+ if (adviceObject is IInterceptor)
+ {
+ // so well-known it doesn't even need an adapter...
+ return new DefaultPointcutAdvisor(adviceObject);
+ }
- ///
- /// Register the given .
- ///
- ///
- /// An that
- /// understands the particular advisor and advice types.
- ///
- public virtual void RegisterAdvisorAdapter(IAdvisorAdapter adapter)
- {
- this.adapters.Add(adapter);
- }
- }
+ foreach (IAdvisorAdapter adapter in this.adapters)
+ {
+ // check that it is supported...
+ if (adapter.SupportsAdvice(adviceObject))
+ {
+ return new DefaultPointcutAdvisor(adviceObject);
+ }
+ }
+
+ throw new UnknownAdviceTypeException(advice);
+ }
+
+ ///
+ /// Returns an to
+ /// allow the use of the supplied in an
+ /// interception-based framework.
+ ///
+ /// The advisor to find an interceptor for.
+ ///
+ /// An interceptor to expose this advisor's behaviour.
+ ///
+ ///
+ /// If the advisor type is not understood by any registered
+ /// .
+ ///
+ public virtual IInterceptor GetInterceptor(IAdvisor advisor)
+ {
+ IAdvice advice = advisor.Advice;
+ if (advice is IInterceptor)
+ {
+ return (IInterceptor) advice;
+ }
+
+ foreach (IAdvisorAdapter adapter in this.adapters)
+ {
+ if (adapter.SupportsAdvice(advice))
+ {
+ return adapter.GetInterceptor(advisor);
+ }
+ }
+
+ throw new UnknownAdviceTypeException(advice);
+ }
+
+ ///
+ /// Register the given .
+ ///
+ ///
+ /// An that
+ /// understands the particular advisor and advice types.
+ ///
+ public virtual void RegisterAdvisorAdapter(IAdvisorAdapter adapter)
+ {
+ this.adapters.Add(adapter);
+ }
}
diff --git a/src/Spring/Spring.Aop/Aop/Framework/Adapter/GlobalAdvisorAdapterRegistry.cs b/src/Spring/Spring.Aop/Aop/Framework/Adapter/GlobalAdvisorAdapterRegistry.cs
index 21395ccb..d65a8116 100644
--- a/src/Spring/Spring.Aop/Aop/Framework/Adapter/GlobalAdvisorAdapterRegistry.cs
+++ b/src/Spring/Spring.Aop/Aop/Framework/Adapter/GlobalAdvisorAdapterRegistry.cs
@@ -18,48 +18,47 @@
#endregion
-namespace Spring.Aop.Framework.Adapter
+namespace Spring.Aop.Framework.Adapter;
+
+///
+/// Provides Singleton-style access to the default
+/// instance.
+///
+/// Rod Johnson
+/// Aleksandar Seovic (.NET)
+[Serializable]
+public sealed class GlobalAdvisorAdapterRegistry : DefaultAdvisorAdapterRegistry
{
+ private static readonly GlobalAdvisorAdapterRegistry instance
+ = new GlobalAdvisorAdapterRegistry();
+
///
- /// Provides Singleton-style access to the default
- /// instance.
+ /// The default instance.
///
- /// Rod Johnson
- /// Aleksandar Seovic (.NET)
- [Serializable]
- public sealed class GlobalAdvisorAdapterRegistry : DefaultAdvisorAdapterRegistry
+ public static GlobalAdvisorAdapterRegistry Instance
{
- private static readonly GlobalAdvisorAdapterRegistry instance
- = new GlobalAdvisorAdapterRegistry();
-
- ///
- /// The default instance.
- ///
- public static GlobalAdvisorAdapterRegistry Instance
- {
- get { return instance; }
- }
-
- #region Constructor (s) / Destructor
-
- // CLOVER:OFF
-
- ///
- /// Creates a new instance of the
- /// class.
- ///
- ///
- ///
- /// This contructor is marked as to enforce the
- /// Singleton pattern
- ///
- ///
- private GlobalAdvisorAdapterRegistry()
- {
- }
-
- // CLOVER:ON
-
- #endregion
+ get { return instance; }
}
+
+ #region Constructor (s) / Destructor
+
+ // CLOVER:OFF
+
+ ///
+ /// Creates a new instance of the
+ /// class.
+ ///
+ ///
+ ///
+ /// This contructor is marked as to enforce the
+ /// Singleton pattern
+ ///
- /// Implementors can create AOP Alliance
- /// s from custom advice
- /// types, enabling these advice types to be used in the Spring.NET AOP
- /// framework, which uses interception under the covers.
- ///
- ///
- /// There is no need for most Spring.NET users to implement this interface;
- /// do so only if you need to introduce more
- /// or
- /// types to Spring.NET.
- ///
- ///
- /// Rod Johnson
- /// Aleksandar Seovic (.NET)
- public interface IAdvisorAdapter
- {
- ///
- /// Does this adapter understand the supplied ?
- ///
- ///
- ///
- /// Is it valid to invoke the
- ///
- /// method with the given advice as an argument?
- ///
- ///
- ///
- /// such as
- /// .
- ///
- /// if this adapter understands the
- /// supplied .
- ///
- bool SupportsAdvice(IAdvice advice);
+namespace Spring.Aop.Framework.Adapter;
- ///
- /// Return an AOP Alliance
- /// exposing the
- /// behaviour of the given advice to an interception-based AOP
- /// framework.
- ///
- ///
- ///
- /// Don't worry about any
- /// contained in the supplied ;
- /// the AOP framework will take care of checking the pointcut.
- ///
- ///
- ///
- /// The advice. The
- ///
- /// method must have previously returned on the
- /// supplied .
- ///
- ///
- /// An AOP Alliance
- /// exposing the
- /// behaviour of the given advice to an interception-based AOP
- /// framework.
- ///
- IInterceptor GetInterceptor(IAdvisor advisor);
- }
-}
\ No newline at end of file
+///
+/// Permits the handling of new advisors and advice types as extensions to
+/// the Spring AOP framework.
+///
+///
+///
+/// Implementors can create AOP Alliance
+/// s from custom advice
+/// types, enabling these advice types to be used in the Spring.NET AOP
+/// framework, which uses interception under the covers.
+///
+///
+/// There is no need for most Spring.NET users to implement this interface;
+/// do so only if you need to introduce more
+/// or
+/// types to Spring.NET.
+///
+///
+/// Rod Johnson
+/// Aleksandar Seovic (.NET)
+public interface IAdvisorAdapter
+{
+ ///
+ /// Does this adapter understand the supplied ?
+ ///
+ ///
+ ///
+ /// Is it valid to invoke the
+ ///
+ /// method with the given advice as an argument?
+ ///
+ ///
+ ///
+ /// such as
+ /// .
+ ///
+ /// if this adapter understands the
+ /// supplied .
+ ///
+ bool SupportsAdvice(IAdvice advice);
+
+ ///
+ /// Return an AOP Alliance
+ /// exposing the
+ /// behaviour of the given advice to an interception-based AOP
+ /// framework.
+ ///
+ ///
+ ///
+ /// Don't worry about any
+ /// contained in the supplied ;
+ /// the AOP framework will take care of checking the pointcut.
+ ///
+/// Implementations must also automatically register adapters for
+/// types.
+///
+///
+/// This is an SPI interface, that should not need to be implemented by any
+/// Spring.NET user.
+///
+///
+/// Rod Johnson
+/// Aleksandar Seovic (.NET)
+public interface IAdvisorAdapterRegistry
{
///
- /// A registry of
- /// instances.
+ /// Returns an wrapping the supplied
+ /// .
+ ///
+ ///
+ /// The object that should be an advice, such as
+ /// or
+ /// .
+ ///
+ ///
+ /// An wrapping the supplied
+ /// . Never returns . If
+ /// the parameter is an
+ /// , it will simply be returned.
+ ///
+ ///
+ /// If no registered
+ /// can wrap
+ /// the supplied .
+ ///
+ IAdvisor Wrap(object advice);
+
+ ///
+ /// Returns an to
+ /// allow the use of the supplied in an
+ /// interception-based framework.
///
///
///
- /// Implementations must also automatically register adapters for
- /// types.
+ /// Don't worry about the pointcut associated with the
+ /// ; if it's an
+ /// , just return an
+ /// interceptor.
///
- ///
- /// This is an SPI interface, that should not need to be implemented by any
- /// Spring.NET user.
- ///
///
- /// Rod Johnson
- /// Aleksandar Seovic (.NET)
- public interface IAdvisorAdapterRegistry
- {
- ///
- /// Returns an wrapping the supplied
- /// .
- ///
- ///
- /// The object that should be an advice, such as
- /// or
- /// .
- ///
- ///
- /// An wrapping the supplied
- /// . Never returns . If
- /// the parameter is an
- /// , it will simply be returned.
- ///
- ///
- /// If no registered
- /// can wrap
- /// the supplied .
- ///
- IAdvisor Wrap(object advice);
+ ///
+ /// The advisor to find an interceptor for.
+ ///
+ ///
+ /// An interceptor to expose this advisor's behaviour.
+ ///
+ ///
+ /// If the advisor type is not understood by any registered
+ /// .
+ ///
+ IInterceptor GetInterceptor(IAdvisor advisor);
- ///
- /// Returns an to
- /// allow the use of the supplied in an
- /// interception-based framework.
- ///
- ///
- ///
- /// Don't worry about the pointcut associated with the
- /// ; if it's an
- /// , just return an
- /// interceptor.
- ///
- ///
- ///
- /// The advisor to find an interceptor for.
- ///
- ///
- /// An interceptor to expose this advisor's behaviour.
- ///
- ///
- /// If the advisor type is not understood by any registered
- /// .
- ///
- IInterceptor GetInterceptor(IAdvisor advisor);
-
- ///
- /// Register the given .
- ///
- ///
- ///
- /// Note that it is not necessary to register adapters for
- /// instances: these
- /// must be automatically recognized by an
- ///
- /// implementation.
- ///
- ///
- ///
- /// An that
- /// understands the particular advisor and advice types.
- ///
- void RegisterAdvisorAdapter(IAdvisorAdapter adapter);
- }
-}
\ No newline at end of file
+ ///
+ /// Register the given .
+ ///
+ ///
+ ///
+ /// Note that it is not necessary to register adapters for
+ /// instances: these
+ /// must be automatically recognized by an
+ ///
+ /// implementation.
+ ///
+ ///
+ ///
+ /// An that
+ /// understands the particular advisor and advice types.
+ ///
+ void RegisterAdvisorAdapter(IAdvisorAdapter adapter);
+}
diff --git a/src/Spring/Spring.Aop/Aop/Framework/Adapter/MethodBeforeAdviceInterceptor.cs b/src/Spring/Spring.Aop/Aop/Framework/Adapter/MethodBeforeAdviceInterceptor.cs
index cafc93ed..347b7e57 100644
--- a/src/Spring/Spring.Aop/Aop/Framework/Adapter/MethodBeforeAdviceInterceptor.cs
+++ b/src/Spring/Spring.Aop/Aop/Framework/Adapter/MethodBeforeAdviceInterceptor.cs
@@ -25,67 +25,66 @@ using Spring.Util;
#endregion
-namespace Spring.Aop.Framework.Adapter
+namespace Spring.Aop.Framework.Adapter;
+
+///
+/// implementation that
+/// wraps instances.
+///
+///
+///
+/// In the future Spring.NET may also offer a more efficient alternative
+/// solution in cases where there is no interception advice and therefore
+/// no need to create an
+/// object.
+///
+///
+/// Used internally by the Spring.NET AOP framework: application developers
+/// should not need to use this class directly.
+///
+///
+/// Rod Johnson
+/// Aleksandar Seovic (.NET)
+[Serializable]
+internal sealed class MethodBeforeAdviceInterceptor : IMethodInterceptor
{
+ private IMethodBeforeAdvice advice;
+
///
- /// implementation that
- /// wraps instances.
+ /// Creates a new instance of the
+ ///
+ /// class.
///
- ///
- ///
- /// In the future Spring.NET may also offer a more efficient alternative
- /// solution in cases where there is no interception advice and therefore
- /// no need to create an
- /// object.
- ///
- ///
- /// Used internally by the Spring.NET AOP framework: application developers
- /// should not need to use this class directly.
- ///
- ///
- /// Rod Johnson
- /// Aleksandar Seovic (.NET)
- [Serializable]
- internal sealed class MethodBeforeAdviceInterceptor : IMethodInterceptor
+ ///
+ /// The that is to be wrapped.
+ ///
+ ///
+ /// If the supplied is .
+ ///
+ public MethodBeforeAdviceInterceptor(IMethodBeforeAdvice advice)
{
- private IMethodBeforeAdvice advice;
+ AssertUtils.ArgumentNotNull(advice, "advice");
+ this.advice = advice;
+ }
- ///
- /// Creates a new instance of the
- ///
- /// class.
- ///
- ///
- /// The that is to be wrapped.
- ///
- ///
- /// If the supplied is .
- ///
- public MethodBeforeAdviceInterceptor(IMethodBeforeAdvice advice)
- {
- AssertUtils.ArgumentNotNull(advice, "advice");
- this.advice = advice;
- }
-
- ///
- /// Executes interceptor before the target method successfully returns.
- ///
- ///
- /// The method invocation that is being intercepted.
- ///
- ///
- /// The result of the call to the
- /// method of
- /// the supplied .
- ///
- ///
- /// If any of the interceptors in the chain or the target object itself
- /// throws an exception.
- ///
- public object Invoke(IMethodInvocation invocation)
- {
- advice.Before(invocation.Method, invocation.Arguments, invocation.This);
- return invocation.Proceed();
- }
+ ///
+ /// Executes interceptor before the target method successfully returns.
+ ///
+ ///
+ /// The method invocation that is being intercepted.
+ ///
+ ///
+ /// The result of the call to the
+ /// method of
+ /// the supplied .
+ ///
+ ///
+ /// If any of the interceptors in the chain or the target object itself
+ /// throws an exception.
+ ///
+ public object Invoke(IMethodInvocation invocation)
+ {
+ advice.Before(invocation.Method, invocation.Arguments, invocation.This);
+ return invocation.Proceed();
}
}
diff --git a/src/Spring/Spring.Aop/Aop/Framework/Adapter/ThrowsAdviceAdapter.cs b/src/Spring/Spring.Aop/Aop/Framework/Adapter/ThrowsAdviceAdapter.cs
index 28bdd9b0..d089b81f 100644
--- a/src/Spring/Spring.Aop/Aop/Framework/Adapter/ThrowsAdviceAdapter.cs
+++ b/src/Spring/Spring.Aop/Aop/Framework/Adapter/ThrowsAdviceAdapter.cs
@@ -25,54 +25,53 @@ using AopAlliance.Intercept;
#endregion
-namespace Spring.Aop.Framework.Adapter
+namespace Spring.Aop.Framework.Adapter;
+
+///
+/// implementation
+/// to enable to be used in the
+/// Spring.NET AOP framework.
+///
+/// Rod Johnson
+/// Aleksandar Seovic (.NET)
+[Serializable]
+internal class ThrowsAdviceAdapter : IAdvisorAdapter
{
///
- /// implementation
- /// to enable to be used in the
- /// Spring.NET AOP framework.
+ /// Returns if the supplied
+ /// is an instance of the
+ /// interface.
///
- /// Rod Johnson
- /// Aleksandar Seovic (.NET)
- [Serializable]
- internal class ThrowsAdviceAdapter : IAdvisorAdapter
+ /// The advice to check.
+ ///
+ /// if the supplied is
+ /// an instance of the interface;
+ /// if not or if the supplied
+ /// is .
+ ///
+ public virtual bool SupportsAdvice(IAdvice advice)
{
- ///
- /// Returns if the supplied
- /// is an instance of the
- /// interface.
- ///
- /// The advice to check.
- ///
- /// if the supplied is
- /// an instance of the interface;
- /// if not or if the supplied
- /// is .
- ///
- public virtual bool SupportsAdvice(IAdvice advice)
- {
- return advice is IThrowsAdvice;
- }
+ return advice is IThrowsAdvice;
+ }
- ///
- /// Wraps the supplied 's
- /// within a
- ///
- /// instance.
- ///
- ///
- /// The advisor exposing the that
- /// is to be wrapped.
- ///
- ///
- /// The supplied 's
- /// wrapped within a
- ///
- /// instance.
- ///
- public virtual IInterceptor GetInterceptor(IAdvisor advisor)
- {
- return new ThrowsAdviceInterceptor(advisor.Advice);
- }
+ ///
+ /// Wraps the supplied 's
+ /// within a
+ ///
+ /// instance.
+ ///
+ ///
+ /// The advisor exposing the that
+ /// is to be wrapped.
+ ///
+ ///
+ /// The supplied 's
+ /// wrapped within a
+ ///
+ /// instance.
+ ///
+ public virtual IInterceptor GetInterceptor(IAdvisor advisor)
+ {
+ return new ThrowsAdviceInterceptor(advisor.Advice);
}
}
diff --git a/src/Spring/Spring.Aop/Aop/Framework/Adapter/ThrowsAdviceInterceptor.cs b/src/Spring/Spring.Aop/Aop/Framework/Adapter/ThrowsAdviceInterceptor.cs
index 787d5df8..bd37fae5 100644
--- a/src/Spring/Spring.Aop/Aop/Framework/Adapter/ThrowsAdviceInterceptor.cs
+++ b/src/Spring/Spring.Aop/Aop/Framework/Adapter/ThrowsAdviceInterceptor.cs
@@ -28,290 +28,292 @@ using Spring.Util;
#endregion
-namespace Spring.Aop.Framework.Adapter
+namespace Spring.Aop.Framework.Adapter;
+
+/// Interceptor to wrap an after throwing advice.
+///
+///
+/// Implementations of the interface
+/// must define methods of the form...
+///
+/// AfterThrowing([MethodInfo method, Object[] args, Object target], Exception subclass);
+///
+/// The method name is fixed (i.e. your methods must be named
+/// AfterThrowing. The first three arguments (as a whole) are
+/// optional, and only useful if futher information about the joinpoint is
+/// required. The return type can be anything, but is almost always
+/// by convention.
+///
+///
+/// Please note that the object encapsulating the throws advice does not
+/// need to implement the interface.
+/// Throws advice methods are discovered via reflection... the
+/// interface serves merely to
+/// discover objects that are to be considered as throws advice.
+/// Other mechanisms for discovering throws advice such as attributes are
+/// also equally valid... all that this class cares about is that a throws
+/// advice object implement one or more methods with a valid throws advice
+/// signature (see above, and the examples below).
+///
+///
+/// This is a framework class that should not normally need to be used
+/// directly by Spring.NET users.
+///
+///
+///
+///
+/// Find below some examples of valid
+/// method signatures...
+///
+///
+/// public class GlobalExceptionHandlingAdvice : IThrowsAdvice
+/// {
+/// public void AfterThrowing(Exception ex) {
+/// // handles absolutely any and every Exception...
+/// }
+/// }
+///
+///
+/// public class RemotingExceptionHandlingAdvice : IThrowsAdvice
+/// {
+/// public void AfterThrowing(RemotingException ex) {
+/// // handles any and every RemotingException (and subclasses of RemotingException)...
+/// }
+/// }
+///
+///
+/// using System.Data;
+///
+/// public class DataExceptionHandlingAdvice
+/// {
+/// public void AfterThrowing(ConstraintException ex) {
+/// // specialised handling of ConstraintExceptions
+/// }
+///
+/// public void AfterThrowing(NoNullAllowedException ex) {
+/// // specialised handling of NoNullAllowedExceptions
+/// }
+///
+/// public void AfterThrowing(DataException ex) {
+/// // handles all other DataExceptions...
+/// }
+/// }
+///
+///
+/// Rod Johnson
+/// Aleksandar Seovic (.NET)
+///
+[Serializable]
+public sealed class ThrowsAdviceInterceptor : IMethodInterceptor
{
- /// Interceptor to wrap an after throwing advice.
+ private static readonly ILogger log = LogManager.GetLogger();
+
+ private const string SpecialThrowingMethodName = "AfterThrowing";
+
+ private readonly object throwsAdvice;
+
+ ///
+ /// The mapping of exception Types to MethodInfo handlers.
+ ///
+ private readonly IDictionary exceptionHandlers;
+
+ ///
+ /// Creates a new instance of the
+ /// class.
+ ///
///
- ///
- /// Implementations of the interface
- /// must define methods of the form...
- ///
- /// AfterThrowing([MethodInfo method, Object[] args, Object target], Exception subclass);
- ///
- /// The method name is fixed (i.e. your methods must be named
- /// AfterThrowing. The first three arguments (as a whole) are
- /// optional, and only useful if futher information about the joinpoint is
- /// required. The return type can be anything, but is almost always
- /// by convention.
- ///
- ///
- /// Please note that the object encapsulating the throws advice does not
- /// need to implement the interface.
- /// Throws advice methods are discovered via reflection... the
- /// interface serves merely to
- /// discover objects that are to be considered as throws advice.
- /// Other mechanisms for discovering throws advice such as attributes are
- /// also equally valid... all that this class cares about is that a throws
- /// advice object implement one or more methods with a valid throws advice
- /// signature (see above, and the examples below).
- ///
- ///
- /// This is a framework class that should not normally need to be used
- /// directly by Spring.NET users.
- ///
///
- ///
- ///
- /// Find below some examples of valid
- /// method signatures...
- ///
- ///
- /// public class GlobalExceptionHandlingAdvice : IThrowsAdvice
- /// {
- /// public void AfterThrowing(Exception ex) {
- /// // handles absolutely any and every Exception...
- /// }
- /// }
- ///
- ///
- /// public class RemotingExceptionHandlingAdvice : IThrowsAdvice
- /// {
- /// public void AfterThrowing(RemotingException ex) {
- /// // handles any and every RemotingException (and subclasses of RemotingException)...
- /// }
- /// }
- ///
- ///
- /// using System.Data;
- ///
- /// public class DataExceptionHandlingAdvice
- /// {
- /// public void AfterThrowing(ConstraintException ex) {
- /// // specialised handling of ConstraintExceptions
- /// }
- ///
- /// public void AfterThrowing(NoNullAllowedException ex) {
- /// // specialised handling of NoNullAllowedExceptions
- /// }
- ///
- /// public void AfterThrowing(DataException ex) {
- /// // handles all other DataExceptions...
- /// }
- /// }
- ///
- ///
- /// Rod Johnson
- /// Aleksandar Seovic (.NET)
- ///
- [Serializable]
- public sealed class ThrowsAdviceInterceptor : IMethodInterceptor
+ ///
+ /// The throws advice to check for exception handler methods.
+ ///
+ ///
+ /// If the supplied is .
+ ///
+ ///
+ /// If no (0) handler methods were discovered on the supplied ;
+ /// or if more than one handler method suitable for a particular
+ /// type was discovered on the supplied
+ /// .
+ ///
+ public ThrowsAdviceInterceptor(object advice)
{
- private static readonly ILogger log = LogManager.GetLogger();
-
- private const string SpecialThrowingMethodName = "AfterThrowing";
-
- private readonly object throwsAdvice;
-
- ///
- /// The mapping of exception Types to MethodInfo handlers.
- ///
- private readonly IDictionary exceptionHandlers;
-
- ///
- /// Creates a new instance of the
- /// class.
- ///
- ///
- ///
- ///
- /// The throws advice to check for exception handler methods.
- ///
- ///
- /// If the supplied is .
- ///
- ///
- /// If no (0) handler methods were discovered on the supplied ;
- /// or if more than one handler method suitable for a particular
- /// type was discovered on the supplied
- /// .
- ///
- public ThrowsAdviceInterceptor(object advice)
+ AssertUtils.ArgumentNotNull(advice, "advice");
+ this.exceptionHandlers = new Hashtable();
+ this.throwsAdvice = advice;
+ MapAllExceptionHandlingMethods(advice);
+ if (exceptionHandlers.Count == 0)
{
- AssertUtils.ArgumentNotNull(advice, "advice");
- this.exceptionHandlers = new Hashtable();
- this.throwsAdvice = advice;
- MapAllExceptionHandlingMethods(advice);
- if (exceptionHandlers.Count == 0)
- {
- throw new ArgumentException(
- "At least one handler method must be found in class ["
- + advice.GetType().FullName + "].");
- }
+ throw new ArgumentException(
+ "At least one handler method must be found in class ["
+ + advice.GetType().FullName + "].");
}
+ }
- private void MapAllExceptionHandlingMethods(object advice)
+ private void MapAllExceptionHandlingMethods(object advice)
+ {
+ MethodInfo[] methods = advice.GetType().GetMethods();
+ foreach (MethodInfo method in methods)
{
- MethodInfo[] methods = advice.GetType().GetMethods();
- foreach (MethodInfo method in methods)
+ int numParams = method.GetParameters().Length;
+ if (method.Name.Equals(SpecialThrowingMethodName)
+ && (numParams == 1 || numParams == 4))
{
- int numParams = method.GetParameters().Length;
- if (method.Name.Equals(SpecialThrowingMethodName)
- && (numParams == 1 || numParams == 4))
+ Type lastParametersType = method.GetParameters()[numParams - 1].ParameterType;
+ if (typeof(Exception).IsAssignableFrom(lastParametersType))
{
- Type lastParametersType = method.GetParameters()[numParams - 1].ParameterType;
- if (typeof (Exception).IsAssignableFrom(lastParametersType))
+ #region Instrumentation
+
+ if (log.IsEnabled(LogLevel.Debug))
{
- #region Instrumentation
-
- if(log.IsEnabled(LogLevel.Debug))
- {
- log.LogDebug("Found exception handler method: " + method);
- }
-
- #endregion
-
- if(this.exceptionHandlers.Contains(lastParametersType))
- {
- throw new ArgumentException(
- "Throws advice handler method for the [" +
- lastParametersType + "] type already exists; don't define " +
- "both single and multiple argument methods for the same " +
- "Exception type in the same class.");
- }
- this.exceptionHandlers[lastParametersType] = method;
+ log.LogDebug("Found exception handler method: " + method);
}
+
+ #endregion
+
+ if (this.exceptionHandlers.Contains(lastParametersType))
+ {
+ throw new ArgumentException(
+ "Throws advice handler method for the [" +
+ lastParametersType + "] type already exists; don't define " +
+ "both single and multiple argument methods for the same " +
+ "Exception type in the same class.");
+ }
+
+ this.exceptionHandlers[lastParametersType] = method;
}
}
}
+ }
- ///
- /// Convenience property that returns the number of exception handler
- /// methods managed by this interceptor.
- ///
- ///
- /// The number of exception handler methods managed by this interceptor.
- ///
- public int HandlerMethodCount
+ ///
+ /// Convenience property that returns the number of exception handler
+ /// methods managed by this interceptor.
+ ///
+ ///
+ /// The number of exception handler methods managed by this interceptor.
+ ///
+ public int HandlerMethodCount
+ {
+ get { return exceptionHandlers.Count; }
+ }
+
+ ///
+ /// Executes interceptor if (and only if) the supplied
+ /// throws an exception that is mapped to
+ /// an appropriate exception handler.
+ ///
+ ///
+ /// The method invocation that is being intercepted.
+ ///
+ ///
+ /// The result of the call to the
+ /// method of
+ /// the supplied (this assumes no
+ /// exception was thrown by the call to the supplied .
+ ///
+ ///
+ /// If any of the interceptors in the chain or the target object itself
+ /// throws an exception.
+ ///
+ ///
+ public object Invoke(IMethodInvocation invocation)
+ {
+ try
{
- get { return exceptionHandlers.Count; }
+ return invocation.Proceed();
+ }
+ catch (TargetInvocationException ex)
+ {
+ // bah, this is a tad gross...
+ Exception realException = ex.InnerException;
+ LookupAndInvokeAnyHandler(realException, invocation);
+ throw realException;
+ }
+ catch (Exception ex)
+ {
+ LookupAndInvokeAnyHandler(ex, invocation);
+ throw;
+ }
+ }
+
+ private void LookupAndInvokeAnyHandler(Exception ex, IMethodInvocation invocation)
+ {
+ MethodInfo handlerMethod = GetExceptionHandler(ex);
+ if (handlerMethod != null)
+ {
+ InvokeHandlerMethod(invocation, ex, handlerMethod);
+ }
+ }
+
+ ///
+ /// Gets the exception handler (if any) that has been mapped to the
+ /// supplied .
+ ///
+ ///
+ ///
+ /// Will return if not found.
+ ///
+ ///
+ ///
+ /// The exception handler for the of the
+ /// supplied given exception.
+ ///
+ /// exception that was thrown
+ private MethodInfo GetExceptionHandler(Exception exception)
+ {
+ Type exceptionClass = exception.GetType();
+
+ #region Instrumentation
+
+ if (log.IsEnabled(LogLevel.Debug))
+ {
+ log.LogDebug("Trying to find handler for exception of type [" + exception.GetType().Name + "].");
}
- ///
- /// Executes interceptor if (and only if) the supplied
- /// throws an exception that is mapped to
- /// an appropriate exception handler.
- ///
- ///
- /// The method invocation that is being intercepted.
- ///
- ///
- /// The result of the call to the
- /// method of
- /// the supplied (this assumes no
- /// exception was thrown by the call to the supplied .
- ///
- ///
- /// If any of the interceptors in the chain or the target object itself
- /// throws an exception.
- ///
- ///
- public object Invoke(IMethodInvocation invocation)
+ #endregion
+
+ MethodInfo handler = (MethodInfo) this.exceptionHandlers[exceptionClass];
+ while (handler == null && !exceptionClass.Equals(typeof(Exception)))
{
- try
- {
- return invocation.Proceed();
- }
- catch (TargetInvocationException ex)
- {
- // bah, this is a tad gross...
- Exception realException = ex.InnerException;
- LookupAndInvokeAnyHandler(realException, invocation);
- throw realException;
- }
- catch (Exception ex)
- {
- LookupAndInvokeAnyHandler(ex, invocation);
- throw;
- }
+ exceptionClass = exceptionClass.BaseType;
+ handler = (MethodInfo) this.exceptionHandlers[exceptionClass];
}
- private void LookupAndInvokeAnyHandler(Exception ex, IMethodInvocation invocation)
+ return handler;
+ }
+
+ ///
+ /// Invokes handler method with appropriate number of parameters
+ ///
+ ///
+ /// The original method invocation that was intercepted.
+ ///
+ ///
+ /// The exception that triggered this interceptor.
+ ///
+ ///
+ /// The exception handler method to invoke.
+ ///
+ private void InvokeHandlerMethod(
+ IMethodInvocation invocation, Exception triggeringException, MethodInfo handlerMethod)
+ {
+ object[] handlerArgs;
+ if (handlerMethod.GetParameters().Length == 1)
{
- MethodInfo handlerMethod = GetExceptionHandler(ex);
- if (handlerMethod != null)
- {
- InvokeHandlerMethod(invocation, ex, handlerMethod);
- }
+ handlerArgs = new object[] { triggeringException };
+ }
+ else
+ {
+ handlerArgs = new object[] { invocation.Method, invocation.Arguments, invocation.This, triggeringException };
}
- ///
- /// Gets the exception handler (if any) that has been mapped to the
- /// supplied .
- ///
- ///
- ///
- /// Will return if not found.
- ///
- ///
- ///
- /// The exception handler for the of the
- /// supplied given exception.
- ///
- /// exception that was thrown
- private MethodInfo GetExceptionHandler(Exception exception)
+ try
{
- Type exceptionClass = exception.GetType();
-
- #region Instrumentation
-
- if(log.IsEnabled(LogLevel.Debug))
- {
- log.LogDebug("Trying to find handler for exception of type [" + exception.GetType().Name + "].");
- }
-
- #endregion
-
- MethodInfo handler = (MethodInfo) this.exceptionHandlers[exceptionClass];
- while (handler == null && !exceptionClass.Equals(typeof(Exception)))
- {
- exceptionClass = exceptionClass.BaseType;
- handler = (MethodInfo) this.exceptionHandlers[exceptionClass];
- }
- return handler;
+ handlerMethod.Invoke(this.throwsAdvice, handlerArgs);
}
-
- ///
- /// Invokes handler method with appropriate number of parameters
- ///
- ///
- /// The original method invocation that was intercepted.
- ///
- ///
- /// The exception that triggered this interceptor.
- ///
- ///
- /// The exception handler method to invoke.
- ///
- private void InvokeHandlerMethod(
- IMethodInvocation invocation, Exception triggeringException, MethodInfo handlerMethod)
+ catch (TargetInvocationException ex)
{
- object[] handlerArgs;
- if (handlerMethod.GetParameters().Length == 1)
- {
- handlerArgs = new object[] {triggeringException};
- }
- else
- {
- handlerArgs = new object[] {invocation.Method, invocation.Arguments, invocation.This, triggeringException};
- }
- try
- {
- handlerMethod.Invoke(this.throwsAdvice, handlerArgs);
- }
- catch (TargetInvocationException ex)
- {
- throw ReflectionUtils.UnwrapTargetInvocationException(ex);
- }
+ throw ReflectionUtils.UnwrapTargetInvocationException(ex);
}
}
}
diff --git a/src/Spring/Spring.Aop/Aop/Framework/Adapter/UnknownAdviceTypeException.cs b/src/Spring/Spring.Aop/Aop/Framework/Adapter/UnknownAdviceTypeException.cs
index ffc69489..3a31b6c7 100644
--- a/src/Spring/Spring.Aop/Aop/Framework/Adapter/UnknownAdviceTypeException.cs
+++ b/src/Spring/Spring.Aop/Aop/Framework/Adapter/UnknownAdviceTypeException.cs
@@ -24,69 +24,68 @@ using System.Runtime.Serialization;
#endregion
-namespace Spring.Aop.Framework.Adapter
+namespace Spring.Aop.Framework.Adapter;
+
+///
+/// Exception thrown when an attempt is made to use an unsupported
+/// or
+/// type.
+///
+/// Rod Johnson
+/// Aleksandar Seovic (.NET)
+[Serializable]
+public class UnknownAdviceTypeException : ArgumentException
{
///
- /// Exception thrown when an attempt is made to use an unsupported
- /// or
- /// type.
+ /// Creates a new instance of the
+ /// class.
///
- /// Rod Johnson
- /// Aleksandar Seovic (.NET)
- [Serializable]
- public class UnknownAdviceTypeException : ArgumentException
+ public UnknownAdviceTypeException()
{
- ///
- /// Creates a new instance of the
- /// class.
- ///
- public UnknownAdviceTypeException()
- {
- }
+ }
- ///
- /// Creates a new instance of the
- /// class.
- ///
- /// The advice that caused the exception.
- public UnknownAdviceTypeException(object advice)
- : base("No adapter for IAdvice of type ["
- + (advice != null ? advice.GetType().FullName : "null") + "].")
- {
- }
+ ///
+ /// Creates a new instance of the
+ /// class.
+ ///
+ /// The advice that caused the exception.
+ public UnknownAdviceTypeException(object advice)
+ : base("No adapter for IAdvice of type ["
+ + (advice != null ? advice.GetType().FullName : "null") + "].")
+ {
+ }
- ///
- /// Creates a new instance of the
- /// class with
- /// the specified message.
- ///
- ///
- /// A message about the exception.
- ///
- public UnknownAdviceTypeException(string message) : base(message)
- {
- }
+ ///
+ /// Creates a new instance of the
+ /// class with
+ /// the specified message.
+ ///
+ ///
+ /// A message about the exception.
+ ///
+ public UnknownAdviceTypeException(string message) : base(message)
+ {
+ }
- ///
- /// Creates a new instance of the
- /// class with
- /// the specified message and root cause.
- ///
- ///
- /// A message about the exception.
- ///
- ///
- /// The root exception that is being wrapped.
- ///
- public UnknownAdviceTypeException(string message, Exception rootCause)
- : base(message, rootCause)
- {
- }
+ ///
+ /// Creates a new instance of the
+ /// class with
+ /// the specified message and root cause.
+ ///
+ ///
+ /// A message about the exception.
+ ///
+ ///
+ /// The root exception that is being wrapped.
+ ///
+ public UnknownAdviceTypeException(string message, Exception rootCause)
+ : base(message, rootCause)
+ {
+ }
- ///
- protected UnknownAdviceTypeException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
+ ///
+ protected UnknownAdviceTypeException(SerializationInfo info, StreamingContext context)
+ : base(info, context)
+ {
}
}
diff --git a/src/Spring/Spring.Aop/Aop/Framework/AdvisedSupport.cs b/src/Spring/Spring.Aop/Aop/Framework/AdvisedSupport.cs
index 904a07ed..822d38ff 100644
--- a/src/Spring/Spring.Aop/Aop/Framework/AdvisedSupport.cs
+++ b/src/Spring/Spring.Aop/Aop/Framework/AdvisedSupport.cs
@@ -21,1638 +21,1665 @@
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
-
using AopAlliance.Aop;
using AopAlliance.Intercept;
-
using Spring.Aop.Support;
using Spring.Aop.Target;
using Spring.Util;
-namespace Spring.Aop.Framework
+namespace Spring.Aop.Framework;
+
+///
+/// Superclass for AOP proxy configuration managers.
+///
+///
+///
+/// Instances of this class are not themselves AOP proxies, but
+/// subclasses of this class are normally factories from which AOP proxy
+/// instances are obtained directly.
+///
+///
+/// This class frees subclasses of the housekeeping of
+/// and
+/// instances, but doesn't actually
+/// implement proxy creation methods, the functionality for which
+/// is provided by subclasses.
+///
+///
+/// Rod Johnson
+/// Aleksandar Seovic (.NET)
+///
+[Serializable]
+public class AdvisedSupport : ProxyConfig, IAdvised
{
+ /// The list of advice.
+ ///
+ ///
+ /// If an is added, it
+ /// will be wrapped in an advice before being added to this list.
+ ///
+ ///
+ private List _advisors = new List();
+
///
- /// Superclass for AOP proxy configuration managers.
+ /// Array updated on changes to the advisors list, which is easier to
+ /// manipulate internally
+ ///
+ private volatile IAdvisor[] _advisorsArray = new IAdvisor[] { };
+
+ ///
+ /// List of introductions.
+ ///
+ private List _introductions = new List();
+
+ ///
+ /// Interface map specifying which object should interface methods be
+ /// delegated to.
///
///
///
- /// Instances of this class are not themselves AOP proxies, but
- /// subclasses of this class are normally factories from which AOP proxy
- /// instances are obtained directly.
- ///
- ///
- /// This class frees subclasses of the housekeeping of
- /// and
- /// instances, but doesn't actually
- /// implement proxy creation methods, the functionality for which
- /// is provided by subclasses.
+ /// If entry value is methods should be delegated
+ /// to the target object.
///
///
- /// Rod Johnson
- /// Aleksandar Seovic (.NET)
- ///
- [Serializable]
- public class AdvisedSupport : ProxyConfig, IAdvised
+ private readonly Dictionary interfaceMap = new Dictionary();
+
+ ///
+ /// The for this instance.
+ ///
+ protected internal ITargetSource m_targetSource = EmptyTargetSource.Empty;
+
+ ///
+ /// Set to when the first AOP proxy has been
+ /// created, meaning that we must track advice changes via the
+ /// OnAdviceChange() callback.
+ ///
+ private bool isActive;
+
+ private Type cachedProxyType;
+ private ConstructorInfo cachedProxyConstructor;
+
+ ///
+ /// The list of event listeners.
+ ///
+ private readonly List listeners = new List();
+
+ ///
+ /// The advisor chain factory.
+ ///
+ private IAdvisorChainFactory advisorChainFactory;
+
+ ///
+ /// If no explicit interfaces are specified, interfaces will be automatically determined
+ /// from the target type
+ ///
+ private bool autoDetectInterfaces;
+
+ ///
+ /// Creates a new instance of the
+ /// class using the
+ /// default advisor chain factory.
+ ///
+ public AdvisedSupport()
{
- /// The list of advice.
- ///
- ///
- /// If an is added, it
- /// will be wrapped in an advice before being added to this list.
- ///
- ///
- private List _advisors = new List();
+ this.advisorChainFactory = new HashtableCachingAdvisorChainFactory();
+ this.AddListener(this.advisorChainFactory);
+ this.autoDetectInterfaces = true;
+ }
- ///
- /// Array updated on changes to the advisors list, which is easier to
- /// manipulate internally
- ///
- private volatile IAdvisor[] _advisorsArray = new IAdvisor[] { };
-
- ///
- /// List of introductions.
- ///
- private List _introductions = new List();
-
- ///
- /// Interface map specifying which object should interface methods be
- /// delegated to.
- ///
- ///
- ///
- /// If entry value is methods should be delegated
- /// to the target object.
- ///
- ///
- private readonly Dictionary interfaceMap = new Dictionary();
-
- ///
- /// The for this instance.
- ///
- protected internal ITargetSource m_targetSource = EmptyTargetSource.Empty;
-
- ///
- /// Set to when the first AOP proxy has been
- /// created, meaning that we must track advice changes via the
- /// OnAdviceChange() callback.
- ///
- private bool isActive;
-
- private Type cachedProxyType;
- private ConstructorInfo cachedProxyConstructor;
-
- ///
- /// The list of event listeners.
- ///
- private readonly List listeners = new List();
-
- ///
- /// The advisor chain factory.
- ///
- private IAdvisorChainFactory advisorChainFactory;
-
- ///
- /// If no explicit interfaces are specified, interfaces will be automatically determined
- /// from the target type
- ///
- private bool autoDetectInterfaces;
-
- ///
- /// Creates a new instance of the
- /// class using the
- /// default advisor chain factory.
- ///
- public AdvisedSupport()
+ ///
+ /// Creates a new instance of the
+ /// class.
+ ///
+ /// The interfaces that are to be proxied.
+ ///
+ /// If this
+ ///
+ public AdvisedSupport(Type[] interfaces)
+ : this()
+ {
+ if (interfaces != null)
{
- this.advisorChainFactory = new HashtableCachingAdvisorChainFactory();
- this.AddListener(this.advisorChainFactory);
- this.autoDetectInterfaces = true;
- }
-
- ///
- /// Creates a new instance of the
- /// class.
- ///
- /// The interfaces that are to be proxied.
- ///
- /// If this
- ///
- public AdvisedSupport(Type[] interfaces)
- : this()
- {
- if (interfaces != null)
- {
- foreach (Type intf in interfaces)
- {
- AddInterfaceInternal(intf);
- }
- }
- }
-
- ///
- /// Creates a new instance of the
- /// class that proxys all of the interfaces exposed by the supplied
- /// .
- ///
- /// The object to proxy.
- ///
- /// If the is .
- ///
- public AdvisedSupport(object target)
- : this(GetInterfaces(target))
- {
- Target = target;
- }
-
- ///
- /// Creates a new instance of the
- /// class that proxys all of the interfaces exposed by the supplied
- /// 's target.
- ///
- /// The providing access to the object to proxy.
- ///
- /// If the is .
- ///
- public AdvisedSupport(ITargetSource targetSource)
- : this(GetInterfaces(targetSource != null ? targetSource.TargetType : null))
- {
- TargetSource = targetSource;
- }
-
- ///
- protected AdvisedSupport(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- _advisors = (List) info.GetValue("advisors", typeof(List));
- _advisorsArray = (IAdvisor[]) info.GetValue("advisorsArray", typeof(IAdvisor[]));
- _introductions = (List) info.GetValue("introductions", typeof(List));
-
- var map = (Dictionary) info.GetValue("interfaceMap", typeof(Dictionary));
- interfaceMap = new Dictionary();
- foreach (var pair in map)
- {
- interfaceMap[Type.GetType(pair.Key)] = pair.Value;
- }
- m_targetSource = (ITargetSource) info.GetValue("targetSource", typeof(ITargetSource));
- isActive = info.GetBoolean("isActive");
- listeners = (List) info.GetValue("listeners", typeof(List));
- advisorChainFactory = (IAdvisorChainFactory) info.GetValue("advisorChainFactory", typeof(IAdvisorChainFactory));
- autoDetectInterfaces = info.GetBoolean("autoDetectInterfaces");
- }
-
- ///
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
- info.AddValue("advisors", _advisors);
- info.AddValue("advisorsArray", _advisorsArray);
- info.AddValue("introductions", _introductions);
- var map = new Dictionary();
- foreach (var pair in interfaceMap)
- {
- map.Add(pair.Key.AssemblyQualifiedName, pair.Value);
- }
- info.AddValue("interfaceMap", map);
- info.AddValue("targetSource", m_targetSource);
- info.AddValue("isActive", isActive);
- info.AddValue("listeners", listeners);
- info.AddValue("advisorChainFactory", advisorChainFactory);
- info.AddValue("autoDetectInterfaces", autoDetectInterfaces);
- }
-
- ///
- /// Gets and sets the
- ///
- /// implementation that will be used to get the interceptor
- /// chains for the advised
- /// .
- ///
- ///
- /// The
- /// implementation that will be used to get the interceptor
- /// chains for the advised
- /// .
- ///
- public virtual IAdvisorChainFactory AdvisorChainFactory
- {
- get
- {
- lock (this.SyncRoot)
- {
- return this.advisorChainFactory;
- }
- }
- set
- {
- AssertUtils.ArgumentNotNull(value, "AdvisorChainFactory");
- lock (this.SyncRoot)
- {
- if (this.advisorChainFactory != null)
- {
- RemoveListener(this.advisorChainFactory);
- }
- this.advisorChainFactory = value;
- AddListener(this.advisorChainFactory);
- }
- }
- }
-
- ///
- /// Returns the current used
- /// by this object.
- ///
- ///
- /// The used by this
- /// object.
- ///
- ///
- public ITargetSource TargetSource
- {
- get { return this.m_targetSource; }
- set
- {
- m_targetSource= (value != null) ? value : EmptyTargetSource.Empty;
- }
- }
-
- ///
- /// Returns a boolean specifying if this
- /// instance can be serialized.
- ///
- ///
- /// true if this instance can be serialized, false otherwise.
- ///
- public virtual bool IsSerializable
- {
- get
- {
- bool canBeSerialized = TargetSource.TargetType.IsSerializable;
- if (!canBeSerialized) return false;
-
- lock (this.SyncRoot)
- {
- IAdvisor[] advisorsArray = this._advisorsArray;
-
- for (int i = 0; i < advisorsArray.Length; i++)
- {
- IAdvisor advisor = advisorsArray[i];
- canBeSerialized = advisor.GetType().IsSerializable
- && advisor.Advice.GetType().IsSerializable;
- if (!canBeSerialized) return false;
- }
-
- for (int i = 0; i < this._introductions.Count; i++)
- {
- IIntroductionAdvisor advisor = this._introductions[i];
- canBeSerialized = advisor.GetType().IsSerializable
- && advisor.Advice.GetType().IsSerializable;
- if (!canBeSerialized) return false;
- }
- }
-
- return true;
- }
- }
-
- ///
- /// Returns the collection of interface s
- /// to be (or that are being) proxied by this proxy.
- ///
- ///
- /// The collection of interface s
- /// to be (or that are being) proxied by this proxy.
- ///
- ///
- public virtual IList Interfaces
- {
- get
- {
- lock (this.SyncRoot)
- {
- Type[] proxiedInterfaces = new Type[this.interfaceMap.Keys.Count];
- this.interfaceMap.Keys.CopyTo(proxiedInterfaces, 0);
- return proxiedInterfaces;
- }
- }
- set
- {
- lock (this.SyncRoot)
- {
- DieIfFrozen("Cannot change interface list if frozen");
- SetInterfacesInternal(value);
- }
- }
- }
-
- ///
- /// Set interfaces to be proxied, bypassing locking and
- ///
- protected void SetInterfacesInternal(IList value)
- {
- this.interfaceMap.Clear();
- if (value != null)
- {
- for (int i = 0; i < value.Count; i++)
- {
- AddInterfaceInternal(value[i]);
- }
- }
- InterfacesChanged();
- }
-
- ///
- /// Returns the mapping of the proxied interface
- /// s to their delegates.
- ///
- ///
- /// The mapping of the proxied interface
- /// s to their delegates.
- ///
- ///
- public virtual IDictionary InterfaceMap
- {
- get
- {
- lock (SyncRoot)
- {
- var dictionary = new Dictionary(interfaceMap.Count);
- foreach (var entry in interfaceMap)
- {
- dictionary[entry.Key] = entry.Value;
- }
- return dictionary;
- }
- }
- }
-
- ///
- /// Is the supplied (interface)
- /// proxied?
- ///
- ///
- /// The interface to test.
- ///
- ///
- /// if the supplied
- /// (interface) is proxied;
- /// if not or the supplied
- /// is .
- ///
- ///
- public virtual bool IsInterfaceProxied(Type intf)
- {
- if (intf != null)
- {
- lock (this.SyncRoot)
- {
- foreach (Type proxyInterface in this.interfaceMap.Keys)
- {
- if (intf.IsAssignableFrom(proxyInterface))
- {
- return true;
- }
- }
- }
- }
- return false;
- }
-
- ///
- /// Returns the collection of
- /// instances that have been applied to this proxy.
- ///
- ///
- /// The collection of
- /// instances that have been applied to this proxy.
- ///
- ///
- public virtual IList Advisors
- {
- get { return _advisorsArray; }
- }
-
- ///
- /// Returns the collection of
- /// instances that have been applied to this proxy.
- ///
- ///
- ///
- /// Will never return , but may return an
- /// empty array (in the case where no
- /// instances have been
- /// applied to this proxy).
- ///
- ///
- ///
- /// The collection of
- /// instances that have been applied to this proxy.
- ///
- ///
- public virtual IList Introductions
- {
- get
- {
- lock (this.SyncRoot)
- {
- return this._introductions;
- }
- }
- }
-
- ///
- /// Adds the supplied to the end (or tail)
- /// of the advice (interceptor) chain.
- ///
- ///
- /// The to be added.
- ///
- ///
- ///
- public void AddAdvice(IAdvice advice)
- {
- //int position = this._advisors != null ? this._advisors.Count : 0;
- AddAdvice(-1, advice);
- }
-
- ///
- /// Adds the supplied to the supplied
- /// in the advice (interceptor) chain.
- ///
- ///
- /// The zero (0) indexed position (from the head) at which the
- /// supplied is to be inserted into the
- /// advice (interceptor) chain.
- ///
- ///
- /// The to be added.
- ///
- ///
- /// If the supplied is ;
- /// or is not an
- /// reference; or if the supplied is a
- /// .
- ///
- ///
- ///
- public void AddAdvice(int position, IAdvice advice)
- {
- if (advice is IInterceptor && !(advice is IMethodInterceptor))
- {
- throw new AopConfigException(
- GetType().FullName + " can only handle AOP Alliance IMethodInterceptor advice.");
- }
- if (advice is IIntroductionInterceptor)
- {
- throw
- new AopConfigException(
- "IIntroductionInterceptors may only be added as part of IIntroductionAdvisor.");
- }
-
- AddAdvisor(position, new DefaultPointcutAdvisor(advice));
- }
-
- ///
- /// Return the index (0 based) of the supplied
- /// in the interceptor
- /// (advice) chain for this proxy.
- ///
- ///
- /// The to search for.
- ///
- ///
- /// The zero (0) based index of this advisor, or -1 if the
- /// supplied is not an advisor for this
- /// proxy.
- ///
- public virtual int IndexOf(IAdvisor advisor)
- {
- lock (this.SyncRoot)
- {
- return IndexOfInternal(advisor);
- }
- }
-
- ///
- /// Return the index (0 based) of the supplied
- /// in the introductions
- /// for this proxy.
- ///
- ///
- /// The to search for.
- ///
- ///
- /// The zero (0) based index of this advisor, or -1 if the
- /// supplied is not an introduction advisor
- /// for this proxy.
- ///
- public virtual int IndexOf(IIntroductionAdvisor advisor)
- {
- lock (this.SyncRoot)
- {
- return IndexOfInternal(advisor);
- }
- }
-
- ///
- /// Removes the supplied the list of advisors
- /// for this proxy.
- ///
- /// The advisor to remove.
- ///
- /// if advisor was found in the list of
- /// for this
- /// proxy and was successfully removed; if not
- /// or if the supplied is .
- ///
- ///
- /// If this proxy configuration is frozen and the
- /// cannot be removed.
- ///
- public bool RemoveAdvisor(IAdvisor advisor)
- {
- DieIfFrozen("Cannot remove advisor: config is frozen");
- bool wasRemoved = false;
- if (advisor != null)
- {
- lock (this.SyncRoot)
- {
- int index = IndexOf(advisor);
- if (index == -1)
- {
- wasRemoved = false;
- }
- else
- {
- RemoveAdvisorInternal(index);
- wasRemoved = true;
- }
- }
- }
- return wasRemoved;
- }
-
- ///
- /// Removes the at the supplied
- /// in the
- /// list
- /// from the list of
- /// for this proxy.
- ///
- ///
- /// The index of the to remove.
- ///
- ///
- /// If this proxy configuration is frozen and the
- /// at the supplied
- /// cannot be removed; or if the supplied is out of
- /// range.
- ///
- public virtual void RemoveAdvisor(int index)
- {
- DieIfFrozen("Cannot remove advisor: config is frozen");
- lock (this.SyncRoot)
- {
- RemoveAdvisorInternal(index);
- }
- }
-
- ///
- /// Removes the supplied from the list
- /// of .
- ///
- ///
- /// The to remove.
- ///
- ///
- /// if the supplied was
- /// found in the list of
- /// and successfully removed.
- ///
- ///
- /// If this proxy configuration is frozen and the
- /// cannot be removed.
- ///
- public bool RemoveAdvice(IAdvice advice)
- {
- lock (this.SyncRoot)
- {
- int index = IndexOf(advice);
- if (index == -1)
- {
- return false;
- }
- RemoveAdvisorInternal(index);
- return true;
- }
- }
-
- ///
- /// Removes the supplied from the list
- /// of .
- ///
- ///
- /// The to remove.
- ///
- ///
- /// if the supplied was
- /// found in the list of
- /// and successfully removed.
- ///
- ///
- /// If this proxy configuration is frozen and the
- /// cannot be removed.
- ///
- public bool RemoveIntroduction(IIntroductionAdvisor introduction)
- {
- DieIfFrozen("Cannot remove introduction: config is frozen");
- bool wasRemoved = false;
- if (introduction != null)
- {
- lock (this.SyncRoot)
- {
- int index = IndexOf(introduction);
- if (index == -1)
- {
- wasRemoved = false;
- }
- else
- {
- RemoveIntroduction(index);
- wasRemoved = true;
- }
- }
- }
- return wasRemoved;
- }
-
- ///
- /// Removes the at the supplied
- /// in the list of
- /// for this proxy.
- ///
- /// The index of the advisor to remove.
- ///
- ///
- /// If this proxy configuration is frozen and the
- /// at the supplied
- /// cannot be removed; or if the supplied
- /// is out of range.
- ///
- public virtual void RemoveIntroduction(int index)
- {
- DieIfFrozen("Cannot remove introduction: config is frozen");
- lock (this.SyncRoot)
- {
- if (index < 0 || index >= _introductions.Count)
- {
- throw new AopConfigException(
- "Introduction index " + index + " is out of bounds: Only have " + _introductions.Count +
- " introductions.");
- }
- IIntroductionAdvisor advisor = _introductions[index];
- // remove all interfaces introduced by the advisor...
- foreach (Type intf in advisor.Interfaces)
- {
- RemoveInterface(intf);
- }
- this._introductions.RemoveAt(index);
- }
- }
-
- ///
- /// Adds the supplied to the list
- /// of .
- ///
- ///
- /// The index in the
- /// list at which the supplied
- /// is to be inserted. If -1, appends to the end of the list.
- ///
- ///
- /// The to add.
- ///
- ///
- /// If this proxy configuration is frozen and the
- /// cannot be added.
- ///
- public virtual void AddAdvisor(int index, IAdvisor advisor)
- {
- DieIfFrozen("Cannot add advisor: config is frozen");
- lock (this.SyncRoot)
- {
- // advisor already in list (SPRNET-846)
- if (_advisors.Contains(advisor)) return;
-
- if (index == -1)
- {
- this._advisors.Add(advisor);
- }
- else
- {
- this._advisors.Insert(index, advisor);
- }
- UpdateAdvisorsArray();
- AdviceChanged();
- }
- }
-
- ///
- /// Adds the supplied to the list
- /// of .
- ///
- ///
- /// The to add.
- ///
- ///
- /// If this proxy configuration is frozen and the
- /// cannot be added.
- ///
- public virtual void AddAdvisor(IAdvisor advisor)
- {
- AddAdvisor(this._advisors.Count, advisor);
- }
-
- ///
- /// Adds the advisors from the supplied
- /// to the list of .
- ///
- ///
- /// The to add advisors from.
- ///
- ///
- /// If this proxy configuration is frozen and the
- /// cannot be added.
- ///
- public void AddAdvisors(IAdvisors advisors)
- {
- foreach (IAdvisor advisor in advisors.Advisors)
- {
- if (advisor is IIntroductionAdvisor)
- {
- AddIntroduction((IIntroductionAdvisor)advisor);
- }
- else
- {
- AddAdvisor(advisor);
- }
- }
- }
-
- ///
- /// Adds the supplied to the list
- /// of .
- ///
- ///
- /// The index in the
- /// list at which the supplied
- /// is to be inserted.
- ///
- ///
- /// The to add.
- ///
- ///
- /// If this proxy configuration is frozen and the
- /// cannot be added.
- ///
- public virtual void AddIntroduction(int index, IIntroductionAdvisor introductionAdvisor)
- {
- DieIfFrozen("Cannot add introduction: config is frozen");
- introductionAdvisor.ValidateInterfaces();
-
- lock (this.SyncRoot)
- {
- if (index < this._introductions.Count)
- {
- this._introductions.RemoveAt(index);
- }
- this._introductions.Insert(index, introductionAdvisor);
-
- int intfCount = this.interfaceMap.Count;
- // If the advisor passed validation we can make the change
- foreach (Type intf in introductionAdvisor.Interfaces)
- {
- this.interfaceMap[intf] = introductionAdvisor;
- }
- if (this.interfaceMap.Count != intfCount)
- {
- InterfacesChanged();
- }
- }
- }
-
- ///
- /// Adds the supplied to the list
- /// of .
- ///
- ///
- /// The to add.
- ///
- ///
- /// If this proxy configuration is frozen and the
- /// cannot be added.
- ///
- public virtual void AddIntroduction(IIntroductionAdvisor introductionAdvisor)
- {
- Type introductionType = introductionAdvisor.Advice.GetType();
- lock (this.SyncRoot)
- {
- int pos = this._introductions.Count;
- for (int i = 0; i < pos; i++)
- {
- IIntroductionAdvisor introduction = this._introductions[i];
- if (introduction.Advice.GetType() == introductionType)
- {
- pos = i;
- }
- }
- AddIntroduction(pos, introductionAdvisor);
- }
- }
-
- ///
- /// Replaces the that
- /// exists at the supplied in the list of
- ///
- /// with the supplied .
- ///
- ///
- /// The index of the
- /// in the list of
- ///
- /// that is to be replaced.
- ///
- ///
- /// The new (replacement) .
- ///
- ///
- /// If the supplied is out of range.
- ///
- public virtual void ReplaceIntroduction(int index, IIntroductionAdvisor introduction)
- {
- lock (this.SyncRoot)
- {
- if (index < 0 || index >= _introductions.Count)
- {
- throw new AopConfigException(
- "Introduction index " + index + " is out of bounds:" +
- " there are currently " + _introductions.Count +
- " introductions.");
- }
-
- _introductions[index] = introduction;
- }
- }
-
- ///
- /// Replaces the with the
- /// .
- ///
- ///
- /// The original (old) advisor to be replaced.
- ///
- ///
- /// The new advisor to replace the with.
- ///
- ///
- /// if the was
- /// replaced; if the was not found in the
- /// advisors collection (or the is
- /// , this method returns
- /// and (effectively) does nothing.
- ///
- ///
- /// If this proxy configuration is frozen and the
- /// cannot be replaced.
- ///
- ///
- public bool ReplaceAdvisor(IAdvisor oldAdvisor, IAdvisor newAdvisor)
- {
- DieIfFrozen("Cannot replace advisor: config is frozen.");
- lock (this.SyncRoot)
- {
- int index = IndexOf(oldAdvisor);
- if (index == -1 || newAdvisor == null)
- {
- return false;
- }
- RemoveAdvisor(index);
- AddAdvisor(index, newAdvisor);
- }
- return true;
- }
-
- ///
- /// As will normally be passed straight through
- /// to the advised target, this method returns the
- /// equivalent for the AOP proxy itself.
- ///
- /// To override this format, override
- ///
- /// A description of the proxy configuration.
- ///
- public string ToProxyConfigString()
- {
- lock (this.SyncRoot)
- {
- return ToProxyConfigStringInternal();
- }
- }
-
- ///
- /// Returns textual information about this configuration object
- ///
- ///
- protected virtual string ToProxyConfigStringInternal()
- {
- StringBuilder buffer = new StringBuilder(this.GetType().FullName + ":\n");
- buffer.Append(this.interfaceMap.Count + " interfaces=[");
- this.InterfacesToString(buffer);
- buffer.Append("];\n");
- buffer.Append(this._advisors.Count + " pointcuts=[");
- this.AdvisorsToString(buffer);
- buffer.Append("];\n");
- buffer.Append("targetSource=[" + this.m_targetSource + "];\n");
- buffer.Append("advisorChainFactory=" + this.advisorChainFactory + ";\n");
- buffer.Append(base.ToString());
- return buffer.ToString();
- }
-
- ///
- /// Gets the target type behind the implementing object.
- /// Ttypically a proxy configuration or an actual proxy.
- ///
- /// The type of the target or null if not known.
- public Type TargetType
- {
- get { return TargetSource.TargetType; }
- }
-
- ///
- /// If no explicit interfaces are specified, interfaces will be automatically determined
- /// from the target type on proxy creation. Defaults to true
- ///
- public bool AutoDetectInterfaces
- {
- get { return autoDetectInterfaces; }
- set { autoDetectInterfaces = value; }
- }
-
- ///
- /// Sets the target object that is to be advised.
- ///
- ///
- ///
- /// This is a convenience write-only property that allows client code
- /// to set the target object... the target object will be implicitly
- /// wrapped within a new
- /// instance.
- ///
- ///
- public virtual object Target
- {
- set { TargetSource = new SingletonTargetSource(value); }
- }
-
- ///
- /// Called by subclasses to get a value indicating whether any AOP proxies have been created yet.
- ///
- /// true if this AOp proxies have been created; otherwise, false.
- protected bool IsActive
- {
- get { return isActive; }
- }
-
- ///
- /// Specifies the of proxies that are to be
- /// created for this instance of proxy config.
- ///
- ///
- ///
- /// If this property value is it simply means that
- /// no proxies have been created yet. Only when the first proxy is
- /// created will this property value be set by the AOP framework.
- ///
- ///
- /// Users will be able to add interceptors dynamically without proxy
- /// regeneration, but if they add introductions the proxy
- /// will have to be regenerated.
- ///
- ///
- ///
- /// The of proxies that are to be
- /// created for this instance of proxy config; if
- /// no proxies have been created yet.
- ///
- internal Type ProxyType
- {
- get { return this.cachedProxyType; }
- set { this.cachedProxyType = value; }
- }
-
- ///
- /// Caches proxy constructor for performance reasons.
- ///
- internal ConstructorInfo ProxyConstructor
- {
- get { return this.cachedProxyConstructor; }
- set { this.cachedProxyConstructor = value; }
- }
-
- ///
- /// Registers the supplied as a listener for
- /// notifications.
- ///
- ///
- /// The to
- /// register.
- ///
- public virtual void AddListener(IAdvisedSupportListener listener)
- {
- lock (this.SyncRoot)
- {
- this.listeners.Add(listener);
- }
- }
-
- ///
- /// Removes the supplied .
- ///
- ///
- /// The to
- /// be removed.
- ///
- public virtual void RemoveListener(IAdvisedSupportListener listener)
- {
- lock (this.SyncRoot)
- {
- this.listeners.Remove(listener);
- }
- }
-
- ///
- /// Adds a new interface to the list of interfaces that are proxied by this proxy.
- ///
- ///
- /// The interface to be proxied by this proxy.
- ///
- ///
- /// If this proxy configuration is frozen
- /// ();
- ///
- ///
- /// If the supplied is .
- ///
- public virtual void AddInterface(Type intf)
- {
- DieIfFrozen("Cannot add interface: configuration is frozen.");
- AssertUtils.ArgumentNotNull(intf, "intf", "Cannot proxy a null interface.");
-
- lock (this.SyncRoot)
+ foreach (Type intf in interfaces)
{
AddInterfaceInternal(intf);
- InterfacesChanged();
}
}
+ }
- ///
- /// Adds a new interface to the list of interfaces that are proxied by this proxy.
- ///
- ///
- /// The interface to be proxied by this proxy.
- ///
- ///
- /// Access is not synchronized.
- ///
- protected virtual void AddInterfaceInternal(Type intf)
+ ///
+ /// Creates a new instance of the
+ /// class that proxys all of the interfaces exposed by the supplied
+ /// .
+ ///
+ /// The object to proxy.
+ ///
+ /// If the is .
+ ///
+ public AdvisedSupport(object target)
+ : this(GetInterfaces(target))
+ {
+ Target = target;
+ }
+
+ ///
+ /// Creates a new instance of the
+ /// class that proxys all of the interfaces exposed by the supplied
+ /// 's target.
+ ///
+ /// The providing access to the object to proxy.
+ ///
+ /// If the is .
+ ///
+ public AdvisedSupport(ITargetSource targetSource)
+ : this(GetInterfaces(targetSource != null ? targetSource.TargetType : null))
+ {
+ TargetSource = targetSource;
+ }
+
+ ///
+ protected AdvisedSupport(SerializationInfo info, StreamingContext context)
+ : base(info, context)
+ {
+ _advisors = (List) info.GetValue("advisors", typeof(List));
+ _advisorsArray = (IAdvisor[]) info.GetValue("advisorsArray", typeof(IAdvisor[]));
+ _introductions = (List) info.GetValue("introductions", typeof(List));
+
+ var map = (Dictionary) info.GetValue("interfaceMap", typeof(Dictionary));
+ interfaceMap = new Dictionary();
+ foreach (var pair in map)
{
- this.interfaceMap[intf] = null;
+ interfaceMap[Type.GetType(pair.Key)] = pair.Value;
}
- ///
- /// Removes the supplied (proxied) .
- ///
- ///
- ///
- /// Does nothing if the supplied (proxied)
- /// isn't proxied.
- ///
- ///
- /// The interface to remove.
- ///
- /// if the interface was removed.
- public virtual bool RemoveInterface(Type intf)
+ m_targetSource = (ITargetSource) info.GetValue("targetSource", typeof(ITargetSource));
+ isActive = info.GetBoolean("isActive");
+ listeners = (List) info.GetValue("listeners", typeof(List));
+ advisorChainFactory = (IAdvisorChainFactory) info.GetValue("advisorChainFactory", typeof(IAdvisorChainFactory));
+ autoDetectInterfaces = info.GetBoolean("autoDetectInterfaces");
+ }
+
+ ///
+ public override void GetObjectData(SerializationInfo info, StreamingContext context)
+ {
+ base.GetObjectData(info, context);
+ info.AddValue("advisors", _advisors);
+ info.AddValue("advisorsArray", _advisorsArray);
+ info.AddValue("introductions", _introductions);
+ var map = new Dictionary();
+ foreach (var pair in interfaceMap)
{
- DieIfFrozen("Cannot remove interface: configuration is frozen.");
- lock (this.SyncRoot)
- {
- if (intf != null && this.interfaceMap.ContainsKey(intf))
- {
- this.interfaceMap.Remove(intf);
- InterfacesChanged();
- return true;
- }
- }
- return false;
+ map.Add(pair.Key.AssemblyQualifiedName, pair.Value);
}
- ///
- /// Return the index (0 based) of the supplied
- /// in the interceptor
- /// (advice) chain for this proxy.
- ///
- ///
- ///
- /// The return value of this method can be used to index into
- /// the
- /// list.
- ///
- ///
- ///
- /// The to search for.
- ///
- ///
- /// The zero (0) based index of this interceptor, or -1 if the
- /// supplied is not an advice for this
- /// proxy.
- ///
- public virtual int IndexOf(IAdvice advice)
+ info.AddValue("interfaceMap", map);
+ info.AddValue("targetSource", m_targetSource);
+ info.AddValue("isActive", isActive);
+ info.AddValue("listeners", listeners);
+ info.AddValue("advisorChainFactory", advisorChainFactory);
+ info.AddValue("autoDetectInterfaces", autoDetectInterfaces);
+ }
+
+ ///
+ /// Gets and sets the
+ ///
+ /// implementation that will be used to get the interceptor
+ /// chains for the advised
+ /// .
+ ///
+ ///
+ /// The
+ /// implementation that will be used to get the interceptor
+ /// chains for the advised
+ /// .
+ ///
+ public virtual IAdvisorChainFactory AdvisorChainFactory
+ {
+ get
{
lock (this.SyncRoot)
{
- return IndexOfInternal(advice);
+ return this.advisorChainFactory;
}
}
-
- ///
- /// Return the index (0 based) of the supplied
- /// in the interceptor
- /// (advice) chain for this proxy.
- ///
- ///
- ///
Acces is not synchronized
- ///
- /// The return value of this method can be used to index into
- /// the
- /// list.
- ///
- ///
- ///
- /// The to search for.
- ///
- ///
- /// The zero (0) based index of this interceptor, or -1 if the
- /// supplied is not an advice for this
- /// proxy.
- ///
- private int IndexOfInternal(IAdvice advice)
+ set
{
- if (this._advisors != null)
- {
- for (int i = 0; i < this._advisors.Count; ++i)
- {
- IAdvisor advisor = this._advisors[i];
- if (advisor.Advice == advice)
- {
- return i;
- }
- }
- }
- return -1;
- }
-
- ///
- /// Return the index (0 based) of the supplied
- /// in the interceptor
- /// (advice) chain for this proxy.
- ///
- ///
- /// The to search for.
- ///
- ///
- /// The zero (0) based index of this advisor, or -1 if the
- /// supplied is not an advisor for this
- /// proxy.
- ///
- ///
- /// Access is not synchronized.
- ///
- private int IndexOfInternal(IAdvisor advisor)
- {
- return this._advisors != null ? this._advisors.IndexOf(advisor) : -1;
- }
-
- ///
- /// Return the index (0 based) of the supplied
- /// in the introductions
- /// for this proxy.
- ///
- ///
- /// The to search for.
- ///
- ///
- /// The zero (0) based index of this advisor, or -1 if the
- /// supplied is not an introduction advisor
- /// for this proxy.
- ///
- ///
- /// Access is not synchronized
- ///
- private int IndexOfInternal(IIntroductionAdvisor advisor)
- {
- return this._introductions.IndexOf(advisor);
- }
-
- ///
- /// Removes the at the supplied
- /// in the
- /// list
- /// from the list of
- /// for this proxy.
- ///
- ///
- /// The index of the to remove.
- ///
- ///
- /// If this proxy configuration is frozen and the
- /// at the supplied
- /// cannot be removed; or if the supplied is out of
- /// range.
- ///
- ///
- /// Does not synchronize access.
- ///
- private void RemoveAdvisorInternal(int index)
- {
- if (index < 0 || index >= this._advisors.Count)
- {
- throw
- new AopConfigException(
- "Advisor index " + index + " is out of bounds: Only have " + this._advisors.Count + " advisors");
- }
- this._advisors.RemoveAt(index);
- this.UpdateAdvisorsArray();
- this.AdviceChanged();
- }
-
- ///
- /// Is the supplied included in any
- /// advisor?
- ///
- ///
- /// The to check for the
- /// inclusion of.
- ///
- ///
- /// if the supplied
- /// could be run in an invocation (this does not imply that said
- /// will be run).
- ///
- public bool AdviceIncluded(IAdvice advice)
- {
- return (IndexOf(advice) != -1);
- }
-
- ///
- /// Returns a count of all of the
- /// type-compatible with the supplied .
- ///
- ///
- /// The of the
- /// to check.
- ///
- ///
- /// A count of all of the
- /// type-compatible with the supplied .
- ///
- public int CountAdviceOfType(Type interceptorType)
- {
- int count = 0;
+ AssertUtils.ArgumentNotNull(value, "AdvisorChainFactory");
lock (this.SyncRoot)
{
- foreach (IAdvisor advisor in this._advisors)
+ if (this.advisorChainFactory != null)
{
- if (interceptorType.IsAssignableFrom(advisor.Advice.GetType()))
- {
- ++count;
- }
+ RemoveListener(this.advisorChainFactory);
+ }
+
+ this.advisorChainFactory = value;
+ AddListener(this.advisorChainFactory);
+ }
+ }
+ }
+
+ ///
+ /// Returns the current used
+ /// by this object.
+ ///
+ ///
+ /// The used by this
+ /// object.
+ ///
+ ///
+ public ITargetSource TargetSource
+ {
+ get { return this.m_targetSource; }
+ set
+ {
+ m_targetSource = (value != null) ? value : EmptyTargetSource.Empty;
+ }
+ }
+
+ ///
+ /// Returns a boolean specifying if this
+ /// instance can be serialized.
+ ///
+ ///
+ /// true if this instance can be serialized, false otherwise.
+ ///
+ public virtual bool IsSerializable
+ {
+ get
+ {
+ bool canBeSerialized = TargetSource.TargetType.IsSerializable;
+ if (!canBeSerialized) return false;
+
+ lock (this.SyncRoot)
+ {
+ IAdvisor[] advisorsArray = this._advisorsArray;
+
+ for (int i = 0; i < advisorsArray.Length; i++)
+ {
+ IAdvisor advisor = advisorsArray[i];
+ canBeSerialized = advisor.GetType().IsSerializable
+ && advisor.Advice.GetType().IsSerializable;
+ if (!canBeSerialized) return false;
+ }
+
+ for (int i = 0; i < this._introductions.Count; i++)
+ {
+ IIntroductionAdvisor advisor = this._introductions[i];
+ canBeSerialized = advisor.GetType().IsSerializable
+ && advisor.Advice.GetType().IsSerializable;
+ if (!canBeSerialized) return false;
}
}
- return count;
- }
- ///
- /// Throws an if
- /// this instances proxy configuration data is frozen.
- ///
- ///
- /// The message that will be passed through to the constructor of any
- /// thrown .
- ///
- ///
- /// If the configuration for this proxy is frozen.
- ///
- ///
- private void DieIfFrozen(string message)
- {
- if (IsFrozen)
- {
- throw new AopConfigException(message);
- }
+ return true;
}
+ }
- ///
- /// Bring the advisors array up to date with the list.
- ///
- private void UpdateAdvisorsArray()
- {
- IAdvisor[] advisorsArray = new IAdvisor[this._advisors.Count];
- this._advisors.CopyTo(advisorsArray, 0);
- this._advisorsArray = advisorsArray;
- }
-
- ///
- /// Callback method that is invoked when the list of proxied interfaces
- /// has changed.
- ///
- ///
- ///
- /// An example of such a change would be when a new introduction is
- /// added. Resetting
- /// to
- /// will cause a new proxy
- /// to be generated on the next call to get a proxy.
- ///
- ///
- protected virtual void InterfacesChanged()
- {
- this.cachedProxyType = null;
- this.cachedProxyConstructor = null;
- if (this.isActive)
- {
- foreach (IAdvisedSupportListener listener in this.listeners)
- {
- listener.InterfacesChanged(this);
- }
- }
- }
-
- ///
- /// Callback method that is invoked when the interceptor list has changed.
- ///
- protected virtual void AdviceChanged()
- {
- if (this.isActive)
- {
- foreach (IAdvisedSupportListener listener in this.listeners)
- {
- listener.AdviceChanged(this);
- }
- }
- }
-
- ///
- /// Activates this instance.
- ///
- protected void Activate()
+ ///
+ /// Returns the collection of interface s
+ /// to be (or that are being) proxied by this proxy.
+ ///
+ ///
+ /// The collection of interface s
+ /// to be (or that are being) proxied by this proxy.
+ ///
+ ///
+ public virtual IList Interfaces
+ {
+ get
{
lock (this.SyncRoot)
{
- this.isActive = true;
- foreach (IAdvisedSupportListener listener in this.listeners)
- {
- listener.Activated(this);
- }
+ Type[] proxiedInterfaces = new Type[this.interfaceMap.Keys.Count];
+ this.interfaceMap.Keys.CopyTo(proxiedInterfaces, 0);
+ return proxiedInterfaces;
}
}
-
- ///
- /// Creates an AOP proxy using this instance's configuration data.
- ///
- ///
- ///
- /// Subclasses must not create a proxy by any other means (at least
- /// without having a well thought out and cogent reason for doing so).
- /// This is because the implementation of this method performs some
- /// required housekeeping logic prior to creating an AOP proxy.
- ///
- ///
- ///
- protected internal virtual IAopProxy CreateAopProxy()
+ set
{
lock (this.SyncRoot)
{
- if (this.autoDetectInterfaces && CountNonIntroductionInterfaces() == 0
-// && !this.ProxyTargetType
- )
- {
- this.interfaceMap.Clear();
- // add all target interfaces
- Type[] targetInterfaces = ReflectionUtils.GetInterfaces(this.TargetType);
- foreach(Type targetInterface in targetInterfaces )
- {
- this.interfaceMap[targetInterface] = null;
- }
- // add introduced interfaces
- foreach(IIntroductionAdvisor introduction in this._introductions)
- {
- foreach(Type introducedInterface in introduction.Interfaces)
- {
- this.interfaceMap[introducedInterface] = introduction;
- }
- }
+ DieIfFrozen("Cannot change interface list if frozen");
+ SetInterfacesInternal(value);
+ }
+ }
+ }
- if (targetInterfaces.Length > 0)
- {
- InterfacesChanged();
- }
- }
-
- if (!this.isActive)
- {
- Activate();
- }
- return AopProxyFactory.CreateAopProxy(this);
+ ///
+ /// Set interfaces to be proxied, bypassing locking and
+ ///
+ protected void SetInterfacesInternal(IList value)
+ {
+ this.interfaceMap.Clear();
+ if (value != null)
+ {
+ for (int i = 0; i < value.Count; i++)
+ {
+ AddInterfaceInternal(value[i]);
}
}
- ///
- /// Calculates the number of not delegating to one of the .
- ///
- private int CountNonIntroductionInterfaces()
+ InterfacesChanged();
+ }
+
+ ///
+ /// Returns the mapping of the proxied interface
+ /// s to their delegates.
+ ///
+ ///
+ /// The mapping of the proxied interface
+ /// s to their delegates.
+ ///
+ ///
+ public virtual IDictionary InterfaceMap
+ {
+ get
{
- int c = 0;
- foreach(Type interfaceType in this.interfaceMap.Keys)
+ lock (SyncRoot)
{
- if (this.interfaceMap[interfaceType] == null)
+ var dictionary = new Dictionary(interfaceMap.Count);
+ foreach (var entry in interfaceMap)
{
- c++;
+ dictionary[entry.Key] = entry.Value;
+ }
+
+ return dictionary;
+ }
+ }
+ }
+
+ ///
+ /// Is the supplied (interface)
+ /// proxied?
+ ///
+ ///
+ /// The interface to test.
+ ///
+ ///
+ /// if the supplied
+ /// (interface) is proxied;
+ /// if not or the supplied
+ /// is .
+ ///
+ ///
+ public virtual bool IsInterfaceProxied(Type intf)
+ {
+ if (intf != null)
+ {
+ lock (this.SyncRoot)
+ {
+ foreach (Type proxyInterface in this.interfaceMap.Keys)
+ {
+ if (intf.IsAssignableFrom(proxyInterface))
+ {
+ return true;
+ }
}
}
- return c;
}
- ///
- /// Copies the configuration from the supplied other
- /// into this instance.
- ///
- ///
- ///
- /// Useful when this instance has been created using the no-argument
- /// constructor, and needs to get all of its confiuration data from
- /// another (most
- /// usually to have an independant copy of said configuration data).
- ///
- ///
- ///
- /// The instance
- /// containing the configiration data that is to be copied into this
- /// instance.
- ///
- protected internal virtual void CopyConfigurationFrom(AdvisedSupport other)
+ return false;
+ }
+
+ ///
+ /// Returns the collection of
+ /// instances that have been applied to this proxy.
+ ///
+ ///
+ /// The collection of
+ /// instances that have been applied to this proxy.
+ ///
+ ///
+ public virtual IList Advisors
+ {
+ get { return _advisorsArray; }
+ }
+
+ ///
+ /// Returns the collection of
+ /// instances that have been applied to this proxy.
+ ///
+ ///
+ ///
+ /// Will never return , but may return an
+ /// empty array (in the case where no
+ /// instances have been
+ /// applied to this proxy).
+ ///
+ ///
+ ///
+ /// The collection of
+ /// instances that have been applied to this proxy.
+ ///
+ ///
+ public virtual IList Introductions
+ {
+ get
{
- CopyConfigurationFrom(other, other.TargetSource, new List(other.Advisors), new List(other.Introductions));
+ lock (this.SyncRoot)
+ {
+ return this._introductions;
+ }
+ }
+ }
+
+ ///
+ /// Adds the supplied to the end (or tail)
+ /// of the advice (interceptor) chain.
+ ///
+ ///
+ /// The to be added.
+ ///
+ ///
+ ///
+ public void AddAdvice(IAdvice advice)
+ {
+ //int position = this._advisors != null ? this._advisors.Count : 0;
+ AddAdvice(-1, advice);
+ }
+
+ ///
+ /// Adds the supplied to the supplied
+ /// in the advice (interceptor) chain.
+ ///
+ ///
+ /// The zero (0) indexed position (from the head) at which the
+ /// supplied is to be inserted into the
+ /// advice (interceptor) chain.
+ ///
+ ///
+ /// The to be added.
+ ///
+ ///
+ /// If the supplied is ;
+ /// or is not an
+ /// reference; or if the supplied is a
+ /// .
+ ///
+ ///
+ ///
+ public void AddAdvice(int position, IAdvice advice)
+ {
+ if (advice is IInterceptor && !(advice is IMethodInterceptor))
+ {
+ throw new AopConfigException(
+ GetType().FullName + " can only handle AOP Alliance IMethodInterceptor advice.");
}
- ///
- /// Copies the configuration from the supplied other
- /// into this instance.
- ///
- ///
- ///
- /// Useful when this instance has been created using the no-argument
- /// constructor, and needs to get all of its confiuration data from
- /// another (most
- /// usually to have an independant copy of said configuration data).
- ///
- ///
- ///
- /// The instance
- /// containing the configiration data that is to be copied into this
- /// instance.
- ///
- /// the new target source
- /// the advisors for the chain
- /// the introductions for the chain
- protected internal virtual void CopyConfigurationFrom(AdvisedSupport other, ITargetSource targetSource, IList advisors, IList introductions)
+ if (advice is IIntroductionInterceptor)
{
- CopyFrom(other);
- this.AdvisorChainFactory = other.advisorChainFactory;
- this.m_targetSource = targetSource;
-// this.cachedProxyType = other.cachedProxyType;
-// this.cachedProxyConstructor = other.cachedProxyConstructor;
- this.Interfaces = new List(other.Interfaces);
- foreach (Type intf in other.interfaceMap.Keys)
+ throw
+ new AopConfigException(
+ "IIntroductionInterceptors may only be added as part of IIntroductionAdvisor.");
+ }
+
+ AddAdvisor(position, new DefaultPointcutAdvisor(advice));
+ }
+
+ ///
+ /// Return the index (0 based) of the supplied
+ /// in the interceptor
+ /// (advice) chain for this proxy.
+ ///
+ ///
+ /// The to search for.
+ ///
+ ///
+ /// The zero (0) based index of this advisor, or -1 if the
+ /// supplied is not an advisor for this
+ /// proxy.
+ ///
+ public virtual int IndexOf(IAdvisor advisor)
+ {
+ lock (this.SyncRoot)
+ {
+ return IndexOfInternal(advisor);
+ }
+ }
+
+ ///
+ /// Return the index (0 based) of the supplied
+ /// in the introductions
+ /// for this proxy.
+ ///
+ ///
+ /// The to search for.
+ ///
+ ///
+ /// The zero (0) based index of this advisor, or -1 if the
+ /// supplied is not an introduction advisor
+ /// for this proxy.
+ ///
+ public virtual int IndexOf(IIntroductionAdvisor advisor)
+ {
+ lock (this.SyncRoot)
+ {
+ return IndexOfInternal(advisor);
+ }
+ }
+
+ ///
+ /// Removes the supplied the list of advisors
+ /// for this proxy.
+ ///
+ /// The advisor to remove.
+ ///
+ /// if advisor was found in the list of
+ /// for this
+ /// proxy and was successfully removed; if not
+ /// or if the supplied is .
+ ///
+ ///
+ /// If this proxy configuration is frozen and the
+ /// cannot be removed.
+ ///
+ public bool RemoveAdvisor(IAdvisor advisor)
+ {
+ DieIfFrozen("Cannot remove advisor: config is frozen");
+ bool wasRemoved = false;
+ if (advisor != null)
+ {
+ lock (this.SyncRoot)
{
- this.interfaceMap[intf] = other.interfaceMap[intf];
+ int index = IndexOf(advisor);
+ if (index == -1)
+ {
+ wasRemoved = false;
+ }
+ else
+ {
+ RemoveAdvisorInternal(index);
+ wasRemoved = true;
+ }
}
- this._advisors = new List();
- foreach (IAdvisor advisor in advisors)
+ }
+
+ return wasRemoved;
+ }
+
+ ///
+ /// Removes the at the supplied
+ /// in the
+ /// list
+ /// from the list of
+ /// for this proxy.
+ ///
+ ///
+ /// The index of the to remove.
+ ///
+ ///
+ /// If this proxy configuration is frozen and the
+ /// at the supplied
+ /// cannot be removed; or if the supplied is out of
+ /// range.
+ ///
+ public virtual void RemoveAdvisor(int index)
+ {
+ DieIfFrozen("Cannot remove advisor: config is frozen");
+ lock (this.SyncRoot)
+ {
+ RemoveAdvisorInternal(index);
+ }
+ }
+
+ ///
+ /// Removes the supplied from the list
+ /// of .
+ ///
+ ///
+ /// The to remove.
+ ///
+ ///
+ /// if the supplied was
+ /// found in the list of
+ /// and successfully removed.
+ ///
+ ///
+ /// If this proxy configuration is frozen and the
+ /// cannot be removed.
+ ///
+ public bool RemoveAdvice(IAdvice advice)
+ {
+ lock (this.SyncRoot)
+ {
+ int index = IndexOf(advice);
+ if (index == -1)
{
- AssertUtils.ArgumentNotNull(advisor, "Advisor must not be null");
- AddAdvisor(advisor);
+ return false;
}
- this._introductions = new List();
- foreach (IIntroductionAdvisor advisor in introductions)
+
+ RemoveAdvisorInternal(index);
+ return true;
+ }
+ }
+
+ ///
+ /// Removes the supplied from the list
+ /// of .
+ ///
+ ///
+ /// The to remove.
+ ///
+ ///
+ /// if the supplied was
+ /// found in the list of
+ /// and successfully removed.
+ ///
+ ///
+ /// If this proxy configuration is frozen and the
+ /// cannot be removed.
+ ///
+ public bool RemoveIntroduction(IIntroductionAdvisor introduction)
+ {
+ DieIfFrozen("Cannot remove introduction: config is frozen");
+ bool wasRemoved = false;
+ if (introduction != null)
+ {
+ lock (this.SyncRoot)
{
- // TODO (EE): implement
-// ValidateIntroductionAdvisor((IIntroductionAdvisor) advisor);
- AssertUtils.ArgumentNotNull(advisor, "IntroductionAdvisor must not be null");
- AddIntroduction(advisor);
+ int index = IndexOf(introduction);
+ if (index == -1)
+ {
+ wasRemoved = false;
+ }
+ else
+ {
+ RemoveIntroduction(index);
+ wasRemoved = true;
+ }
}
+ }
+
+ return wasRemoved;
+ }
+
+ ///
+ /// Removes the at the supplied
+ /// in the list of
+ /// for this proxy.
+ ///
+ /// The index of the advisor to remove.
+ ///
+ ///
+ /// If this proxy configuration is frozen and the
+ /// at the supplied
+ /// cannot be removed; or if the supplied
+ /// is out of range.
+ ///
+ public virtual void RemoveIntroduction(int index)
+ {
+ DieIfFrozen("Cannot remove introduction: config is frozen");
+ lock (this.SyncRoot)
+ {
+ if (index < 0 || index >= _introductions.Count)
+ {
+ throw new AopConfigException(
+ "Introduction index " + index + " is out of bounds: Only have " + _introductions.Count +
+ " introductions.");
+ }
+
+ IIntroductionAdvisor advisor = _introductions[index];
+ // remove all interfaces introduced by the advisor...
+ foreach (Type intf in advisor.Interfaces)
+ {
+ RemoveInterface(intf);
+ }
+
+ this._introductions.RemoveAt(index);
+ }
+ }
+
+ ///
+ /// Adds the supplied to the list
+ /// of .
+ ///
+ ///
+ /// The index in the
+ /// list at which the supplied
+ /// is to be inserted. If -1, appends to the end of the list.
+ ///
+ ///
+ /// The to add.
+ ///
+ ///
+ /// If this proxy configuration is frozen and the
+ /// cannot be added.
+ ///
+ public virtual void AddAdvisor(int index, IAdvisor advisor)
+ {
+ DieIfFrozen("Cannot add advisor: config is frozen");
+ lock (this.SyncRoot)
+ {
+ // advisor already in list (SPRNET-846)
+ if (_advisors.Contains(advisor)) return;
+
+ if (index == -1)
+ {
+ this._advisors.Add(advisor);
+ }
+ else
+ {
+ this._advisors.Insert(index, advisor);
+ }
+
UpdateAdvisorsArray();
AdviceChanged();
}
+ }
- ///
- /// A that represents the current
- /// configuration.
- ///
- ///
- /// A that represents the current
- /// configuration.
- ///
- public override string ToString()
+ ///
+ /// Adds the supplied to the list
+ /// of .
+ ///
+ ///
+ /// The to add.
+ ///
+ ///
+ /// If this proxy configuration is frozen and the
+ /// cannot be added.
+ ///
+ public virtual void AddAdvisor(IAdvisor advisor)
+ {
+ AddAdvisor(this._advisors.Count, advisor);
+ }
+
+ ///
+ /// Adds the advisors from the supplied
+ /// to the list of .
+ ///
+ ///
+ /// The to add advisors from.
+ ///
+ ///
+ /// If this proxy configuration is frozen and the
+ /// cannot be added.
+ ///
+ public void AddAdvisors(IAdvisors advisors)
+ {
+ foreach (IAdvisor advisor in advisors.Advisors)
{
- lock (this.SyncRoot)
+ if (advisor is IIntroductionAdvisor)
{
- return ToProxyConfigString();
+ AddIntroduction((IIntroductionAdvisor) advisor);
+ }
+ else
+ {
+ AddAdvisor(advisor);
+ }
+ }
+ }
+
+ ///
+ /// Adds the supplied to the list
+ /// of .
+ ///
+ ///
+ /// The index in the
+ /// list at which the supplied
+ /// is to be inserted.
+ ///
+ ///
+ /// The to add.
+ ///
+ ///
+ /// If this proxy configuration is frozen and the
+ /// cannot be added.
+ ///
+ public virtual void AddIntroduction(int index, IIntroductionAdvisor introductionAdvisor)
+ {
+ DieIfFrozen("Cannot add introduction: config is frozen");
+ introductionAdvisor.ValidateInterfaces();
+
+ lock (this.SyncRoot)
+ {
+ if (index < this._introductions.Count)
+ {
+ this._introductions.RemoveAt(index);
+ }
+
+ this._introductions.Insert(index, introductionAdvisor);
+
+ int intfCount = this.interfaceMap.Count;
+ // If the advisor passed validation we can make the change
+ foreach (Type intf in introductionAdvisor.Interfaces)
+ {
+ this.interfaceMap[intf] = introductionAdvisor;
+ }
+
+ if (this.interfaceMap.Count != intfCount)
+ {
+ InterfacesChanged();
+ }
+ }
+ }
+
+ ///
+ /// Adds the supplied to the list
+ /// of .
+ ///
+ ///
+ /// The to add.
+ ///
+ ///
+ /// If this proxy configuration is frozen and the
+ /// cannot be added.
+ ///
+ public virtual void AddIntroduction(IIntroductionAdvisor introductionAdvisor)
+ {
+ Type introductionType = introductionAdvisor.Advice.GetType();
+ lock (this.SyncRoot)
+ {
+ int pos = this._introductions.Count;
+ for (int i = 0; i < pos; i++)
+ {
+ IIntroductionAdvisor introduction = this._introductions[i];
+ if (introduction.Advice.GetType() == introductionType)
+ {
+ pos = i;
+ }
+ }
+
+ AddIntroduction(pos, introductionAdvisor);
+ }
+ }
+
+ ///
+ /// Replaces the that
+ /// exists at the supplied in the list of
+ ///
+ /// with the supplied .
+ ///
+ ///
+ /// The index of the
+ /// in the list of
+ ///
+ /// that is to be replaced.
+ ///
+ ///
+ /// The new (replacement) .
+ ///
+ ///
+ /// If the supplied is out of range.
+ ///
+ public virtual void ReplaceIntroduction(int index, IIntroductionAdvisor introduction)
+ {
+ lock (this.SyncRoot)
+ {
+ if (index < 0 || index >= _introductions.Count)
+ {
+ throw new AopConfigException(
+ "Introduction index " + index + " is out of bounds:" +
+ " there are currently " + _introductions.Count +
+ " introductions.");
+ }
+
+ _introductions[index] = introduction;
+ }
+ }
+
+ ///
+ /// Replaces the with the
+ /// .
+ ///
+ ///
+ /// The original (old) advisor to be replaced.
+ ///
+ ///
+ /// The new advisor to replace the with.
+ ///
+ ///
+ /// if the was
+ /// replaced; if the was not found in the
+ /// advisors collection (or the is
+ /// , this method returns
+ /// and (effectively) does nothing.
+ ///
+ ///
+ /// If this proxy configuration is frozen and the
+ /// cannot be replaced.
+ ///
+ ///
+ public bool ReplaceAdvisor(IAdvisor oldAdvisor, IAdvisor newAdvisor)
+ {
+ DieIfFrozen("Cannot replace advisor: config is frozen.");
+ lock (this.SyncRoot)
+ {
+ int index = IndexOf(oldAdvisor);
+ if (index == -1 || newAdvisor == null)
+ {
+ return false;
+ }
+
+ RemoveAdvisor(index);
+ AddAdvisor(index, newAdvisor);
+ }
+
+ return true;
+ }
+
+ ///
+ /// As will normally be passed straight through
+ /// to the advised target, this method returns the
+ /// equivalent for the AOP proxy itself.
+ ///
+ /// To override this format, override
+ ///
+ /// A description of the proxy configuration.
+ ///
+ public string ToProxyConfigString()
+ {
+ lock (this.SyncRoot)
+ {
+ return ToProxyConfigStringInternal();
+ }
+ }
+
+ ///
+ /// Returns textual information about this configuration object
+ ///
+ ///
+ protected virtual string ToProxyConfigStringInternal()
+ {
+ StringBuilder buffer = new StringBuilder(this.GetType().FullName + ":\n");
+ buffer.Append(this.interfaceMap.Count + " interfaces=[");
+ this.InterfacesToString(buffer);
+ buffer.Append("];\n");
+ buffer.Append(this._advisors.Count + " pointcuts=[");
+ this.AdvisorsToString(buffer);
+ buffer.Append("];\n");
+ buffer.Append("targetSource=[" + this.m_targetSource + "];\n");
+ buffer.Append("advisorChainFactory=" + this.advisorChainFactory + ";\n");
+ buffer.Append(base.ToString());
+ return buffer.ToString();
+ }
+
+ ///
+ /// Gets the target type behind the implementing object.
+ /// Ttypically a proxy configuration or an actual proxy.
+ ///
+ /// The type of the target or null if not known.
+ public Type TargetType
+ {
+ get { return TargetSource.TargetType; }
+ }
+
+ ///
+ /// If no explicit interfaces are specified, interfaces will be automatically determined
+ /// from the target type on proxy creation. Defaults to true
+ ///
+ public bool AutoDetectInterfaces
+ {
+ get { return autoDetectInterfaces; }
+ set { autoDetectInterfaces = value; }
+ }
+
+ ///
+ /// Sets the target object that is to be advised.
+ ///
+ ///
+ ///
+ /// This is a convenience write-only property that allows client code
+ /// to set the target object... the target object will be implicitly
+ /// wrapped within a new
+ /// instance.
+ ///
+ ///
+ public virtual object Target
+ {
+ set { TargetSource = new SingletonTargetSource(value); }
+ }
+
+ ///
+ /// Called by subclasses to get a value indicating whether any AOP proxies have been created yet.
+ ///
+ /// true if this AOp proxies have been created; otherwise, false.
+ protected bool IsActive
+ {
+ get { return isActive; }
+ }
+
+ ///
+ /// Specifies the of proxies that are to be
+ /// created for this instance of proxy config.
+ ///
+ ///
+ ///
+ /// If this property value is it simply means that
+ /// no proxies have been created yet. Only when the first proxy is
+ /// created will this property value be set by the AOP framework.
+ ///
+ ///
+ /// Users will be able to add interceptors dynamically without proxy
+ /// regeneration, but if they add introductions the proxy
+ /// will have to be regenerated.
+ ///
+ ///
+ ///
+ /// The of proxies that are to be
+ /// created for this instance of proxy config; if
+ /// no proxies have been created yet.
+ ///
+ internal Type ProxyType
+ {
+ get { return this.cachedProxyType; }
+ set { this.cachedProxyType = value; }
+ }
+
+ ///
+ /// Caches proxy constructor for performance reasons.
+ ///
+ internal ConstructorInfo ProxyConstructor
+ {
+ get { return this.cachedProxyConstructor; }
+ set { this.cachedProxyConstructor = value; }
+ }
+
+ ///
+ /// Registers the supplied as a listener for
+ /// notifications.
+ ///
+ ///
+ /// The to
+ /// register.
+ ///
+ public virtual void AddListener(IAdvisedSupportListener listener)
+ {
+ lock (this.SyncRoot)
+ {
+ this.listeners.Add(listener);
+ }
+ }
+
+ ///
+ /// Removes the supplied .
+ ///
+ ///
+ /// The to
+ /// be removed.
+ ///
+ public virtual void RemoveListener(IAdvisedSupportListener listener)
+ {
+ lock (this.SyncRoot)
+ {
+ this.listeners.Remove(listener);
+ }
+ }
+
+ ///
+ /// Adds a new interface to the list of interfaces that are proxied by this proxy.
+ ///
+ ///
+ /// The interface to be proxied by this proxy.
+ ///
+ ///
+ /// If this proxy configuration is frozen
+ /// ();
+ ///
+ ///
+ /// If the supplied is .
+ ///
+ public virtual void AddInterface(Type intf)
+ {
+ DieIfFrozen("Cannot add interface: configuration is frozen.");
+ AssertUtils.ArgumentNotNull(intf, "intf", "Cannot proxy a null interface.");
+
+ lock (this.SyncRoot)
+ {
+ AddInterfaceInternal(intf);
+ InterfacesChanged();
+ }
+ }
+
+ ///
+ /// Adds a new interface to the list of interfaces that are proxied by this proxy.
+ ///
+ ///
+ /// The interface to be proxied by this proxy.
+ ///
+ ///
+ /// Access is not synchronized.
+ ///
+ protected virtual void AddInterfaceInternal(Type intf)
+ {
+ this.interfaceMap[intf] = null;
+ }
+
+ ///
+ /// Removes the supplied (proxied) .
+ ///
+ ///
+ ///
+ /// Does nothing if the supplied (proxied)
+ /// isn't proxied.
+ ///
+ ///
+ /// The interface to remove.
+ ///
+ /// if the interface was removed.
+ public virtual bool RemoveInterface(Type intf)
+ {
+ DieIfFrozen("Cannot remove interface: configuration is frozen.");
+ lock (this.SyncRoot)
+ {
+ if (intf != null && this.interfaceMap.ContainsKey(intf))
+ {
+ this.interfaceMap.Remove(intf);
+ InterfacesChanged();
+ return true;
}
}
- ///
- /// Helper method that adds the names of all of the proxied interfaces
- /// to the buffer of the supplied .
- ///
- ///
- /// The to append the proxied interface
- /// names to.
- ///
- private void InterfacesToString(StringBuilder buffer)
+ return false;
+ }
+
+ ///
+ /// Return the index (0 based) of the supplied
+ /// in the interceptor
+ /// (advice) chain for this proxy.
+ ///
+ ///
+ ///
+ /// The return value of this method can be used to index into
+ /// the
+ /// list.
+ ///
+ ///
+ ///
+ /// The to search for.
+ ///
+ ///
+ /// The zero (0) based index of this interceptor, or -1 if the
+ /// supplied is not an advice for this
+ /// proxy.
+ ///
+ public virtual int IndexOf(IAdvice advice)
+ {
+ lock (this.SyncRoot)
{
- string separator = string.Empty;
- foreach (Type intf in this.interfaceMap.Keys)
+ return IndexOfInternal(advice);
+ }
+ }
+
+ ///
+ /// Return the index (0 based) of the supplied
+ /// in the interceptor
+ /// (advice) chain for this proxy.
+ ///
+ ///
+ ///
Acces is not synchronized
+ ///
+ /// The return value of this method can be used to index into
+ /// the
+ /// list.
+ ///
+ ///
+ ///
+ /// The to search for.
+ ///
+ ///
+ /// The zero (0) based index of this interceptor, or -1 if the
+ /// supplied is not an advice for this
+ /// proxy.
+ ///
+ private int IndexOfInternal(IAdvice advice)
+ {
+ if (this._advisors != null)
+ {
+ for (int i = 0; i < this._advisors.Count; ++i)
{
- buffer.Append(separator).Append("[").Append(intf.FullName).Append("] -> ");
- IIntroductionAdvisor advisor = this.interfaceMap[intf];
- if (advisor == null)
+ IAdvisor advisor = this._advisors[i];
+ if (advisor.Advice == advice)
{
- if (TargetSource.TargetType != null)
+ return i;
+ }
+ }
+ }
+
+ return -1;
+ }
+
+ ///
+ /// Return the index (0 based) of the supplied
+ /// in the interceptor
+ /// (advice) chain for this proxy.
+ ///
+ ///
+ /// The to search for.
+ ///
+ ///
+ /// The zero (0) based index of this advisor, or -1 if the
+ /// supplied is not an advisor for this
+ /// proxy.
+ ///
+ ///
+ /// Access is not synchronized.
+ ///
+ private int IndexOfInternal(IAdvisor advisor)
+ {
+ return this._advisors != null ? this._advisors.IndexOf(advisor) : -1;
+ }
+
+ ///
+ /// Return the index (0 based) of the supplied
+ /// in the introductions
+ /// for this proxy.
+ ///
+ ///
+ /// The to search for.
+ ///
+ ///
+ /// The zero (0) based index of this advisor, or -1 if the
+ /// supplied is not an introduction advisor
+ /// for this proxy.
+ ///
+ ///
+ /// Access is not synchronized
+ ///
+ private int IndexOfInternal(IIntroductionAdvisor advisor)
+ {
+ return this._introductions.IndexOf(advisor);
+ }
+
+ ///
+ /// Removes the at the supplied
+ /// in the
+ /// list
+ /// from the list of
+ /// for this proxy.
+ ///
+ ///
+ /// The index of the to remove.
+ ///
+ ///
+ /// If this proxy configuration is frozen and the
+ /// at the supplied
+ /// cannot be removed; or if the supplied is out of
+ /// range.
+ ///
+ ///
+ /// Does not synchronize access.
+ ///
+ private void RemoveAdvisorInternal(int index)
+ {
+ if (index < 0 || index >= this._advisors.Count)
+ {
+ throw
+ new AopConfigException(
+ "Advisor index " + index + " is out of bounds: Only have " + this._advisors.Count + " advisors");
+ }
+
+ this._advisors.RemoveAt(index);
+ this.UpdateAdvisorsArray();
+ this.AdviceChanged();
+ }
+
+ ///
+ /// Is the supplied included in any
+ /// advisor?
+ ///
+ ///
+ /// The to check for the
+ /// inclusion of.
+ ///
+ ///
+ /// if the supplied
+ /// could be run in an invocation (this does not imply that said
+ /// will be run).
+ ///
+ public bool AdviceIncluded(IAdvice advice)
+ {
+ return (IndexOf(advice) != -1);
+ }
+
+ ///
+ /// Returns a count of all of the
+ /// type-compatible with the supplied .
+ ///
+ ///
+ /// The of the
+ /// to check.
+ ///
+ ///
+ /// A count of all of the
+ /// type-compatible with the supplied .
+ ///
+ public int CountAdviceOfType(Type interceptorType)
+ {
+ int count = 0;
+ lock (this.SyncRoot)
+ {
+ foreach (IAdvisor advisor in this._advisors)
+ {
+ if (interceptorType.IsAssignableFrom(advisor.Advice.GetType()))
+ {
+ ++count;
+ }
+ }
+ }
+
+ return count;
+ }
+
+ ///
+ /// Throws an if
+ /// this instances proxy configuration data is frozen.
+ ///
+ ///
+ /// The message that will be passed through to the constructor of any
+ /// thrown .
+ ///
+ ///
+ /// If the configuration for this proxy is frozen.
+ ///
+ ///
+ private void DieIfFrozen(string message)
+ {
+ if (IsFrozen)
+ {
+ throw new AopConfigException(message);
+ }
+ }
+
+ ///
+ /// Bring the advisors array up to date with the list.
+ ///
+ private void UpdateAdvisorsArray()
+ {
+ IAdvisor[] advisorsArray = new IAdvisor[this._advisors.Count];
+ this._advisors.CopyTo(advisorsArray, 0);
+ this._advisorsArray = advisorsArray;
+ }
+
+ ///
+ /// Callback method that is invoked when the list of proxied interfaces
+ /// has changed.
+ ///
+ ///
+ ///
+ /// An example of such a change would be when a new introduction is
+ /// added. Resetting
+ /// to
+ /// will cause a new proxy
+ /// to be generated on the next call to get a proxy.
+ ///
+ ///
+ protected virtual void InterfacesChanged()
+ {
+ this.cachedProxyType = null;
+ this.cachedProxyConstructor = null;
+ if (this.isActive)
+ {
+ foreach (IAdvisedSupportListener listener in this.listeners)
+ {
+ listener.InterfacesChanged(this);
+ }
+ }
+ }
+
+ ///
+ /// Callback method that is invoked when the interceptor list has changed.
+ ///
+ protected virtual void AdviceChanged()
+ {
+ if (this.isActive)
+ {
+ foreach (IAdvisedSupportListener listener in this.listeners)
+ {
+ listener.AdviceChanged(this);
+ }
+ }
+ }
+
+ ///
+ /// Activates this instance.
+ ///
+ protected void Activate()
+ {
+ lock (this.SyncRoot)
+ {
+ this.isActive = true;
+ foreach (IAdvisedSupportListener listener in this.listeners)
+ {
+ listener.Activated(this);
+ }
+ }
+ }
+
+ ///
+ /// Creates an AOP proxy using this instance's configuration data.
+ ///
+ ///
+ ///
+ /// Subclasses must not create a proxy by any other means (at least
+ /// without having a well thought out and cogent reason for doing so).
+ /// This is because the implementation of this method performs some
+ /// required housekeeping logic prior to creating an AOP proxy.
+ ///
+ ///
+ ///
+ protected internal virtual IAopProxy CreateAopProxy()
+ {
+ lock (this.SyncRoot)
+ {
+ if (this.autoDetectInterfaces && CountNonIntroductionInterfaces() == 0
+// && !this.ProxyTargetType
+ )
+ {
+ this.interfaceMap.Clear();
+ // add all target interfaces
+ Type[] targetInterfaces = ReflectionUtils.GetInterfaces(this.TargetType);
+ foreach (Type targetInterface in targetInterfaces)
+ {
+ this.interfaceMap[targetInterface] = null;
+ }
+
+ // add introduced interfaces
+ foreach (IIntroductionAdvisor introduction in this._introductions)
+ {
+ foreach (Type introducedInterface in introduction.Interfaces)
{
- buffer.Append("target[").Append(TargetSource.TargetType.FullName).Append("]");
- }
- else
- {
- buffer.Append("target[NOT SPECIFIED (=null)]");
+ this.interfaceMap[introducedInterface] = introduction;
}
}
+
+ if (targetInterfaces.Length > 0)
+ {
+ InterfacesChanged();
+ }
+ }
+
+ if (!this.isActive)
+ {
+ Activate();
+ }
+
+ return AopProxyFactory.CreateAopProxy(this);
+ }
+ }
+
+ ///
+ /// Calculates the number of not delegating to one of the .
+ ///
+ private int CountNonIntroductionInterfaces()
+ {
+ int c = 0;
+ foreach (Type interfaceType in this.interfaceMap.Keys)
+ {
+ if (this.interfaceMap[interfaceType] == null)
+ {
+ c++;
+ }
+ }
+
+ return c;
+ }
+
+ ///
+ /// Copies the configuration from the supplied other
+ /// into this instance.
+ ///
+ ///
+ ///
+ /// Useful when this instance has been created using the no-argument
+ /// constructor, and needs to get all of its confiuration data from
+ /// another (most
+ /// usually to have an independant copy of said configuration data).
+ ///
+ ///
+ ///
+ /// The instance
+ /// containing the configiration data that is to be copied into this
+ /// instance.
+ ///
+ protected internal virtual void CopyConfigurationFrom(AdvisedSupport other)
+ {
+ CopyConfigurationFrom(other, other.TargetSource, new List(other.Advisors), new List(other.Introductions));
+ }
+
+ ///
+ /// Copies the configuration from the supplied other
+ /// into this instance.
+ ///
+ ///
+ ///
+ /// Useful when this instance has been created using the no-argument
+ /// constructor, and needs to get all of its confiuration data from
+ /// another (most
+ /// usually to have an independant copy of said configuration data).
+ ///
+ ///
+ ///
+ /// The instance
+ /// containing the configiration data that is to be copied into this
+ /// instance.
+ ///
+ /// the new target source
+ /// the advisors for the chain
+ /// the introductions for the chain
+ protected internal virtual void CopyConfigurationFrom(AdvisedSupport other, ITargetSource targetSource, IList advisors, IList introductions)
+ {
+ CopyFrom(other);
+ this.AdvisorChainFactory = other.advisorChainFactory;
+ this.m_targetSource = targetSource;
+// this.cachedProxyType = other.cachedProxyType;
+// this.cachedProxyConstructor = other.cachedProxyConstructor;
+ this.Interfaces = new List(other.Interfaces);
+ foreach (Type intf in other.interfaceMap.Keys)
+ {
+ this.interfaceMap[intf] = other.interfaceMap[intf];
+ }
+
+ this._advisors = new List();
+ foreach (IAdvisor advisor in advisors)
+ {
+ AssertUtils.ArgumentNotNull(advisor, "Advisor must not be null");
+ AddAdvisor(advisor);
+ }
+
+ this._introductions = new List();
+ foreach (IIntroductionAdvisor advisor in introductions)
+ {
+ // TODO (EE): implement
+// ValidateIntroductionAdvisor((IIntroductionAdvisor) advisor);
+ AssertUtils.ArgumentNotNull(advisor, "IntroductionAdvisor must not be null");
+ AddIntroduction(advisor);
+ }
+
+ UpdateAdvisorsArray();
+ AdviceChanged();
+ }
+
+ ///
+ /// A that represents the current
+ /// configuration.
+ ///
+ ///
+ /// A that represents the current
+ /// configuration.
+ ///
+ public override string ToString()
+ {
+ lock (this.SyncRoot)
+ {
+ return ToProxyConfigString();
+ }
+ }
+
+ ///
+ /// Helper method that adds the names of all of the proxied interfaces
+ /// to the buffer of the supplied .
+ ///
+ ///
+ /// The to append the proxied interface
+ /// names to.
+ ///
+ private void InterfacesToString(StringBuilder buffer)
+ {
+ string separator = string.Empty;
+ foreach (Type intf in this.interfaceMap.Keys)
+ {
+ buffer.Append(separator).Append("[").Append(intf.FullName).Append("] -> ");
+ IIntroductionAdvisor advisor = this.interfaceMap[intf];
+ if (advisor == null)
+ {
+ if (TargetSource.TargetType != null)
+ {
+ buffer.Append("target[").Append(TargetSource.TargetType.FullName).Append("]");
+ }
else
{
- buffer.Append("introduction[").Append(advisor.Advice.GetType().FullName).Append("]");
+ buffer.Append("target[NOT SPECIFIED (=null)]");
}
- separator = ", ";
}
- }
-
- ///
- /// Helper method that adds advisor's
- /// to the buffer of the supplied .
- ///
- ///
- /// The to append the advisor details to.
- ///
- private void AdvisorsToString(StringBuilder buffer)
- {
- string separator = string.Empty;
- foreach (IAdvisor advisor in this._advisors)
+ else
{
- buffer.Append(separator).Append(advisor);
- separator = ", ";
+ buffer.Append("introduction[").Append(advisor.Advice.GetType().FullName).Append("]");
}
- }
- ///
- /// Gets all of the interfaces implemented by the
- /// of the supplied
- /// .
- ///
- ///
- /// The object to get the interfaces of.
- ///
- ///
- /// All of the interfaces implemented by the
- /// of the supplied
- /// .
- ///
- ///
- /// If the supplied is .
- ///
- protected static Type[] GetInterfaces(object target)
- {
- if (target == null)
- {
- throw new AopConfigException("Can't proxy null object");
- }
- return ReflectionUtils.GetInterfaces(target is Type ? (Type)target : target.GetType());
+ separator = ", ";
}
}
+
+ ///
+ /// Helper method that adds advisor's
+ /// to the buffer of the supplied .
+ ///
+ ///
+ /// The to append the advisor details to.
+ ///
+ private void AdvisorsToString(StringBuilder buffer)
+ {
+ string separator = string.Empty;
+ foreach (IAdvisor advisor in this._advisors)
+ {
+ buffer.Append(separator).Append(advisor);
+ separator = ", ";
+ }
+ }
+
+ ///
+ /// Gets all of the interfaces implemented by the
+ /// of the supplied
+ /// .
+ ///
+ ///
+ /// The object to get the interfaces of.
+ ///
+ ///
+ /// All of the interfaces implemented by the
+ /// of the supplied
+ /// .
+ ///
+ ///
+ /// If the supplied is .
+ ///
+ protected static Type[] GetInterfaces(object target)
+ {
+ if (target == null)
+ {
+ throw new AopConfigException("Can't proxy null object");
+ }
+
+ return ReflectionUtils.GetInterfaces(target is Type ? (Type) target : target.GetType());
+ }
}
diff --git a/src/Spring/Spring.Aop/Aop/Framework/AdvisorChainFactoryUtils.cs b/src/Spring/Spring.Aop/Aop/Framework/AdvisorChainFactoryUtils.cs
index 339a9bfe..05ac2258 100644
--- a/src/Spring/Spring.Aop/Aop/Framework/AdvisorChainFactoryUtils.cs
+++ b/src/Spring/Spring.Aop/Aop/Framework/AdvisorChainFactoryUtils.cs
@@ -21,101 +21,99 @@
#region Imports
using System.Reflection;
-
using AopAlliance.Intercept;
-
using Spring.Aop.Framework.Adapter;
#endregion
-namespace Spring.Aop.Framework
+namespace Spring.Aop.Framework;
+
+///
+/// Utility methods for use by
+/// implementations.
+///
+///
+///
+/// Not intended to be used directly by applications.
+///
+///
+/// Rod Johnson
+/// Aleksandar Seovic (.NET)
+public sealed class AdvisorChainFactoryUtils
{
- ///
- /// Utility methods for use by
- /// implementations.
- ///
- ///
- ///
- /// Not intended to be used directly by applications.
- ///
- ///
- /// Rod Johnson
- /// Aleksandar Seovic (.NET)
- public sealed class AdvisorChainFactoryUtils
- {
- ///
- /// Gets the list of
- /// interceptors and dynamic interception
- /// advice that may apply to the supplied
- /// invocation.
- ///
- /// The proxy configuration.
- /// The object proxy.
- ///
- /// The method to evaluate interceptors for.
- ///
- ///
- /// The of the target object.
- ///
- ///
- /// A of
- /// (if there's
- /// a dynamic method matcher that needs evaluation at runtime).
- ///
- public static IList