What's the difference between functions if() and where() in Windsor Castle. I came across in code these two ways of component registration
1)
container.Register(
Classes.FromAssemblyInThisApplication()
.Where(x=> x.IsClass && x.GetAllInterfaces().Length > 0)
.WithService.AllInterfaces()
.LifestyleSingleton());
2)
container.Register(
Classes.FromAssemblyInThisApplication()
.Pick()
.If(x=> x.IsClass && x.GetAllInterfaces().Length > 0)
.WithService.AllInterfaces()
.LifestyleSingleton());
I wonder what is the difference between these two ways of component registration.
If you look at the source code, you'll see that Where
does (practically) the same thing as Pick()
, additionally adding the call to .If
internally. This is looking at the internal workings of the code, so it's not guaranteed that this won't change for whatever reason at some point.
Where
:
public BasedOnDescriptor Where(Predicate<Type> accepted)
{
var descriptor = new BasedOnDescriptor(typeof(object), this, additionalFilters).If(accepted);
criterias.Add(descriptor);
return descriptor;
}
And Pick
:
public BasedOnDescriptor Pick()
{
return BasedOn<object>();
}
public BasedOnDescriptor BasedOn<T>()
{
return BasedOn(typeof(T));
}
public BasedOnDescriptor BasedOn(Type basedOn)
{
var descriptor = new BasedOnDescriptor(basedOn, this, additionalFilters);
criterias.Add(descriptor);
return descriptor;
}