Good ? Hammett,

  I am not exactly sure.   If anyone knows, speak up or we should report it

On Tue, Dec 23, 2008 at 6:28 PM, hammett <[email protected]> wrote:

>
> Is the bug reported?
>
> On Tue, Dec 23, 2008 at 4:16 PM, Craig Neuwirt <[email protected]> wrote:
> >
> >
> > On Tue, Dec 23, 2008 at 6:11 PM, Mike Nichols <[email protected]>
> > wrote:
> >>
> >> Hi Craig
> >> It turns out I was dealing with two different problems, my
> >> misunderstanding of .WithService and most importantly a bug in the CLR
> >> I saw Bill Pierce posted a patch for a bit ago. The SelectDescriptor
> >> only sanitizes the interface when using .FirstInterface(), so when I
> >> was calling .GetInterfaces() from a .Select() call the interface
> >> definition wasn;t getting handled correctly.
> >
> > Yup, very annoying bug
> >
> >>
> >> It seems like all registrations of services should get passed through
> >> this CLR workaround, yes? If so I can submit a patch that would do
> >> this.
> >
> >  Sure
> >>
> >> When I change my test to the following I am getting the generic
> >> service registered...removing the workaround call makes the test fail:
> >> [TestFixture]
> >>        public class RegistrationTest2
> >>        {
> >>                [Test]
> >>                public void ShouldGetAllLocalTasks()
> >>                {
> >>                        var kernel = new DefaultKernel();
> >>
> >>  kernel.Register(AllTypes.Of<ILocalTask>().FromAssembly
> >> (Assembly.GetExecutingAssembly())
> >>                                                .WithService.Select((t,
> b)
> >> =>
> >>                                                                    from
> >> type in t.GetInterfaces()
> >>                                                                    where
> >> !type.Equals(typeof
> >> (ILocalTask))
> >>
>  select
> >> GetSelectable(type)));
> >>
> >>  Assert.IsNotNull(kernel.Resolve<ILocalGenericTask<object>>());
> >>                }
> >>                public Type GetSelectable(Type check)
> >>                {
> >>                        // This is a workaround for a CLR bug in
> >>                        // which GetInterfaces() returns interfaces
> >>                        // with no implementations.
> >>                        if (check.IsGenericType && check.ReflectedType ==
> >> null)
> >>                        {
> >>                                bool shouldUseGenericTypeDefinition =
> >> false;
> >>                                foreach (Type argument in
> >> check.GetGenericArguments())
> >>                                {
> >>                                        shouldUseGenericTypeDefinition |=
> >> argument.IsGenericParameter;
> >>                                }
> >>                                if (shouldUseGenericTypeDefinition)
> >>                                        return
> >> check.GetGenericTypeDefinition();
> >>                        }
> >>                        return check;
> >>
> >>                }
> >>
> >>
> >>
> >>        }
> >>        public interface ILocalTask { }
> >>        public interface ILocalGenericTask<T1>:ILocalTask{}
> >>        public class Task2<T1> : ILocalGenericTask<T1>{ }
> >>
> >>
> >>
> >>
> >>
> >> On Dec 23, 4:24 pm, "Craig Neuwirt" <[email protected]> wrote:
> >> > I think you want WithService.Base().  What you had orignally would
> >> > register
> >> > the type with the implementation type.
> >> >
> >> > On Tue, Dec 23, 2008 at 4:21 PM, Mike Nichols
> >> > <[email protected]>wrote:
> >> >
> >> >
> >> >
> >> > > OK I got the failing test above working but it seems odd. You have
> to
> >> > > specify '.FromInterface' explicilty but that seems redundant since
> you
> >> > > just specified '.BasedOn':
> >> > > [Test]
> >> > >                public void ShouldGetAllLocalTasks()
> >> > >                {
> >> > >                        var kernel = new DefaultKernel();
> >> > >                        kernel.Register(AllTypes.FromAssembly(typeof
> >> > > (RegistrationTest2).Assembly)
> >> > >                                .BasedOn<ILocalTask>()
> >> > >                                .WithService
> >> > >                                .FromInterface(typeof(ILocalTask)));
> >> > >                        Assert.AreNotEqual<int>(0,
> >> > > kernel.GetHandlers(typeof
> >> > > (ILocalTask)).Length);//pass
> >> > >                 }
> >> >
> >> > > On Dec 23, 11:45 am, Mike Nichols <[email protected]> wrote:
> >> > > > I updated my trunk just a few days old and all my AllTypes
> >> > > > registrations are broken. The first test below fails.
> >> > > > I have tried BasedOn and it is failing too.
> >> > > > I did update .net 2,3,3.5 with the most recent service packs, so
> >> > > > wonder if that might have something to do with it?
> >> > > > Any ideas?
> >> >
> >> > > >                 [Test]
> >> > > >                 public void ShouldGetAllLocalTasks()
> >> > > >                 {
> >> > > >                         kernel = new DefaultKernel();
> >> >
> >> > > kernel.Register(AllTypes.Of<ILocalTask>().FromAssembly
> >> > > > (Assembly.GetExecutingAssembly()));
> >> > > >                         IHandler[] handlers =
> >> > > kernel.GetHandlers(typeof(ILocalTask));
> >> > > >                         Assert.AreNotEqual(0,
> >> > > > handlers.Length);//fails
> >> > > >                 }
> >> > > >                 [Test]
> >> > > >                 public void ShouldRegisterTask()
> >> > > >                 {
> >> > > >                         kernel = new DefaultKernel();
> >> >
> >> > > kernel.Register(Component.For<ILocalTask>().ImplementedBy<Task1>
> >> > > > ());
> >> > > >                         IHandler[] handlers =
> >> > > kernel.GetHandlers(typeof(ILocalTask));
> >> > > >                         Assert.AreNotEqual(0,
> >> > > > handlers.Length);//passes
> >> > > >                 }
> >> > > >                 public interface ILocalTask { }
> >> > > >                 public class Task1 : ILocalTask { }
> >>
> >
> >
> > >
> >
>
>
>
> --
> Cheers,
> hammett
> http://hammett.castleproject.org/
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to