Here is my example:
namespace ExampleGenericInterface
{
using System;
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using Castle.Windsor.Installer;
using NUnit.Framework;
public interface IEntity { }
public abstract class EntityBase : IEntity {}
public class DocEntity : EntityBase { }
public interface IContext { }
public class Context : IContext { }
public interface IGridContext<TEntity> : IContext where TEntity :
IEntity { }
public class GridContext<TEntity> : IGridContext<TEntity> where
TEntity : IEntity { }
public interface IAction<in TContext> where TContext : IContext
{
void Exec(TContext context);
}
public class MyGridAction<TEntity> :
IAction<IGridContext<TEntity>> where TEntity : IEntity
{
public void Exec(IGridContext<TEntity> context)
{
throw new NotImplementedException();
}
}
public class ControllersInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container,
IConfigurationStore store)
{
container.Register(AllTypes.FromThisAssembly()
.BasedOn(typeof(IAction<>))
.WithService.AllInterfaces()
.Configure(c =>
c.LifeStyle.Transient));
}
}
public class TestClass
{
private IWindsorContainer container;
[TestFixtureSetUp]
public void Init()
{
container = new
WindsorContainer().Install(FromAssembly.This());
}
[Test]
public void TestMe()
{
var r1 =
container.ResolveAll<IAction<IGridContext<DocEntity>>>();
Assert.That(r1, Is.Not.Empty);
// Expect to see
IAction<IGridContext<DocEntity>> item = new
MyGridAction<DocEntity>();
// to use in this way: item.Exec(gridContext);
}
}
}
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en.