Added container accessor to Castle.Core
[castle.git] / AspectSharp / AspectSharp.LoggingExample / Application.cs
blob0358c93273b5183c8416ac6f852895b1cd825ce5
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace AspectSharp.LoggingExample
17 using System;
18 using AspectSharp.Builder;
19 using AspectSharp.LoggingExample.Model;
21 /// <summary>
22 /// Sample application demonstrating a very basic use of Aspect#.
23 /// </summary>
24 class Application
26 private static AspectEngine _engine;
28 [STAThread]
29 static void Main(string[] args)
31 //Reading the config from an application configuration file.
32 AppDomainConfigurationBuilder builder = new AppDomainConfigurationBuilder();
34 //Creating the AspectEngine, based on the configuration.
35 _engine = builder.Build();
37 ClassInvocation();
39 Console.WriteLine(" ");
40 Console.WriteLine(" ");
42 InterfaceInvocation();
44 Console.WriteLine("\r\nPress any key to exit." );
45 Console.ReadLine();
48 /// <summary>
49 /// Shows interception of an interface method.
50 /// </summary>
51 private static void InterfaceInvocation()
53 Console.WriteLine("InterfaceInvocation");
55 //Wraping the class which is compatible with the inteface.
56 IAgatKiller agatKiller = _engine.WrapInterface(typeof(IAgatKiller), new Ronin()) as IAgatKiller;
58 agatKiller.KillAgat("Demon's Castle", "Bleed Sword");
61 /// <summary>
62 /// Shows interception of an class method.
63 /// </summary>
64 private static void ClassInvocation()
66 Console.WriteLine("ClassInvocation");
68 //Wraping the class
69 MachineGun machineGun = _engine.WrapClass(typeof(MachineGun)) as MachineGun;
71 //Not intercepted. It isn't a virtual method.
72 machineGun.Fire(5);
74 //Intercepted.
75 machineGun.FireTenTimes();