Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make Castle windsor resolve generics with constraints?
    primarykey
    data
    text
    <pre><code>using System; using Castle.Windsor; using Castle.MicroKernel.Registration; using System.Reflection; using Castle.MicroKernel.Resolvers.SpecializedResolvers; namespace Windsor { class MainClass { public static void Main (string[] args) { var container = new WindsorContainer (); container.Register (Component.For (typeof(IIface&lt;, &gt;)).ImplementedBy (typeof(HandlerImpl&lt;, &gt;))); //container.Register (Component.For (typeof(IIface&lt;, &gt;)).ImplementedBy(typeof(Impl2))); container.Kernel.Resolver.AddSubResolver (new ArrayResolver (container.Kernel)); var normal = container.ResolveAll&lt;IIface&lt;Impl2, Stub&gt;&gt; (); var ex = container.ResolveAll&lt;IIface&lt;Impl1, Stub&gt;&gt; (); //var qwe = new HandlerImpl&lt;Impl1, Stub&gt; (); Console.WriteLine("Hello World!"); } } public class Base {} public class Stub {} public interface AdditionalIface { } public interface IIface&lt;T1, T2&gt; where T1 : Base where T2 : class { T1 Command { get; set; } } public class HandlerImpl&lt;T1, T2&gt; : IIface&lt;T1, T2&gt; where T1 : Base, AdditionalIface where T2 : class { public T1 Command { get; set; } } public class Impl1 : Base { } public class Impl2 : Base, AdditionalIface { } } </code></pre> <p>So, now if i do smth like:</p> <pre><code>var normal = container.ResolveAll&lt;IIface&lt;Impl2, Stub&gt;&gt; (); // this works ok var ex = container.ResolveAll&lt;IIface&lt;Impl1, Stub&gt;&gt; (); // this throws exception abou not fullfilled constraints // instead i want it just show no resolved implementations </code></pre> <p>Is there any way to make this work as I want it to?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload