Difference between revisions of "Unity"
(New page: == The Unity Framework ==) |
(→The Unity Framework) |
||
Line 1: | Line 1: | ||
== The Unity Framework == | == The Unity Framework == | ||
+ | |||
+ | === Interceptor durch Vererbung und virtuelle Methoden == | ||
+ | <source lang="csharp"> | ||
+ | using System; | ||
+ | using System.Collections.Generic; | ||
+ | using System.Linq; | ||
+ | using System.Text; | ||
+ | using Microsoft.Practices.Unity; | ||
+ | using Microsoft.Practices.Unity.Configuration; | ||
+ | using Microsoft.Practices.Unity.InterceptionExtension; | ||
+ | |||
+ | namespace UnityFramework | ||
+ | { | ||
+ | class Program | ||
+ | { | ||
+ | static void Main(string[] args) | ||
+ | { | ||
+ | |||
+ | IUnityContainer container = new UnityContainer(); | ||
+ | container.AddNewExtension<Interception>(); | ||
+ | |||
+ | |||
+ | container.RegisterType<Service>(); | ||
+ | container.Configure<Interception>().SetInterceptorFor<Service>(new VirtualMethodInterceptor()); | ||
+ | |||
+ | var service = container.Resolve<Service>(); | ||
+ | service.DoIt("Hello"); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </source> |
Revision as of 10:06, 9 September 2011
The Unity Framework
= Interceptor durch Vererbung und virtuelle Methoden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using Microsoft.Practices.Unity.InterceptionExtension;
namespace UnityFramework
{
class Program
{
static void Main(string[] args)
{
IUnityContainer container = new UnityContainer();
container.AddNewExtension<Interception>();
container.RegisterType<Service>();
container.Configure<Interception>().SetInterceptorFor<Service>(new VirtualMethodInterceptor());
var service = container.Resolve<Service>();
service.DoIt("Hello");
}
}
}