Click here to Skip to main content
15,893,588 members
Articles / Desktop Programming / WPF

Extending Castle DynamicProxy

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
8 May 2010CPOL7 min read 25.8K   183   12  
Shows how to extend the proxy generated by this framework by using Reflection.Emit.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.Core;
using Castle.Windsor;
using Castle.MicroKernel;
using Castle.MicroKernel.Registration;
using App.Core;
using App.Data;
using System.Collections.ObjectModel;
using PresentationModelBase;
using Castle.DynamicProxy;
using System.Reflection;
using System.Collections.Specialized;
using Castle.MicroKernel.ModelBuilder.Inspectors;
using Castle.Facilities.PresentationModelIntegration;



namespace App.Configuration
{
    public class ConfigurationManager
    {
        internal static DefaultKernel _microkernel = new DefaultKernel();

        public static void Configure()
        {
            AppDomain.CurrentDomain.SetData("servicelocator", _microkernel);
            _microkernel.AddFacility<PresentationModelWpfFacility>();

            
            _microkernel.Register
                (
                Component.For<MainViewPresentationModel, IMainViewPresentationModel>().LifeStyle.Is(LifestyleType.Singleton),
                Component.For<ProductsViewPresentationModel, IEntityCollectionViewPresentationModel<Product>>().LifeStyle.Is(LifestyleType.Singleton),
                Component.For(typeof(DummyDao<>), typeof(IDao<>)).LifeStyle.Is(LifestyleType.Singleton),
                Component.For(typeof(List<>), typeof(IList<>)).LifeStyle.Is(LifestyleType.Transient),
                Component.For<ProductEditViewPresentationModel, IEntityViewPresentationModel<Product>>().LifeStyle.Is(LifestyleType.Transient)
                );
            InsertStubData();
        }
      
        private static void InsertStubData()
        {
            IDao<Product> dao = _microkernel.Resolve<IDao<Product>>();
            Random r = new Random();
            for (int i = 0; i < 10; i++)
            {
                Product p = new Product();
                p.Name = string.Format("Product {0}", i + 1);
                p.Price = r.Next(2, 523);
                dao.SaveOrUpdate(p);
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Brazil Brazil
Software developer specialized in the .NET framework

Comments and Discussions