Sorry for letting this slip under my radar for so long.
Anyway, that is a know problem, and we already have a ticket in the
issue tracker for that (which is over a year old):
http://issues.castleproject.org/issue/IOC-200
Simone Busoli offered to try to tackle it but I don't know if he got
anywhere.
The problem is, it's a complex problem, there's no nice API in .NET to
work with semi-open generics and I suspect coming up with a robust
implementation would be quite hard.
We do accept patches, as always, if you feel like giving it a shot.
Krzysztof
On 31/05/2011 7:22 PM, pil0t wrote:
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.