If you want to restrict both, on base type AND namespace use

BasedOn().If()

that will give you the expected behaviour.

Krzysztof

On 14/08/2011 12:23 PM, Shawn Hinsey wrote:
Yeah, this is one of those areas where fluent APIs become really
tricky to design. I think the only surefire way to prevent this would
be to have the logical operators return a different object that
doesn't allow you to make those calls, but I'm not sure how you'd
achieve that without a lot of other headaches.

That said, I've been using this fluent API since it came out however
long ago and this is the first issue of this nature that I've ever
encountered, so it's definitely doing something right.

Fortunately in my case the need to restrict by namespace like that is
really only a nice-to-have type feature, so for the time being it's no
problem to remove the call. I'll revisit it at some point though.

2011/8/13 Krzysztof Koźmic<[email protected]>:
Yeah, I know, I got burden by that myself on several occasions.
While the goal is noble (register more stuff in a single assembly scan) the
API does not follow principle of least surprise sadly, and I can't think of
a good, clean way, of making it obvious where you're making logical AND
(which is when you're using If() or Unless() methods). and when you're doing
"and also from that assembly I want that separate batch of components".

Krzysztof

On 14/08/2011 12:12 PM, Shawn Hinsey wrote:
Got it, thanks for the help. This was driving me crazy.

2011/8/13 Krzysztof Koźmic<[email protected]>:
Where/BasedOn/Peek are logical ORs in this context, not ANDs
that's explained in the doco.

On 14/08/2011 12:09 PM, Shawn Hinsey wrote:
So to be clear, using Where precludes the use of the other calls?

2011/8/13 Krzysztof Koźmic<[email protected]>:
That's because this core is equivalent to the following:

        Container.Register
                (AllTypes.FromAssembly(myAssembly)

  .Where(Component.IsInNamespace(myDesiredNamespace)));


        Container.Register
                (AllTypes.FromAssembly(myAssembly)
                        .BasedOn(typeof (MyServiceInterface))
                        .Configure(component =>
  component.LifeStyle.Transient)

  .WithService.AllInterfaces().WithService.Self());


This is a very common problem with the API and WIndsor 3 deprecates
this
option (you will get a compiler warning).

On 14/08/2011 11:55 AM, Shawn Hinsey wrote:
Hello,

I have the following registration call.

        Container.Register
                (AllTypes.FromAssembly(myAssembly)

  .Where(Component.IsInNamespace(myDesiredNamespace))
                        .BasedOn(typeof (MyServiceInterface))
                        .Configure(component =>
  component.LifeStyle.Transient)

  .WithService.AllInterfaces().WithService.Self());

But after this call, the container reports the lifestyle all of all of
these instances as undefined and defaulted to singleton, which is
causing problems due to their dependencies on transient components.

I am confident that this should work, based on the documentation and
my experience with Windsor, so am I overlooking here?

Thanks,
Shawn

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


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


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



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