nested generics

8 views
Skip to first unread message

pil0t

unread,
Apr 6, 2012, 3:43:23 AM4/6/12
to castle-pro...@googlegroups.com

Could you help me to make this works?

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();
   
}
}

Here's my installer:

    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));
       
}
   
}

Here is my test:

    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);
       
}
   
}
}

Tomas Lycken

unread,
Apr 6, 2012, 10:08:20 AM4/6/12
to castle-pro...@googlegroups.com
Not if you're not telling us why it doesn't already...

What do you expect the code to do? What does it do instead? What error messages do you get?

// Tomas

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-users/-/zDecwW3eFUsJ.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.

Reply all
Reply to author
Forward
0 new messages