Showing posts with label Typo Error. Show all posts
Showing posts with label Typo Error. Show all posts

Saturday, October 2, 2010

Castle Windsor warning on AddComponentLifeStyle is obsolete

Wrong warning...


Warning 1 'Castle.Windsor.WindsorContainer.AddComponentLifeStyle(string, System.Type, Castle.Core.LifestyleType)' is obsolete: 'Use Register(Component.For(classType).Named(key)).Lifestyle.Is(lifestyle)) instead.' C:\_CODE\SportsStore\SportsStore\Controllers\WindsorControllerFactory.cs 37 17 SportsStore


...for this kind of code:


container.AddComponentLifeStyle(t.FullName, t, LifestyleType.Transient);

If you try to type LifeStyle after of Named(t.FullName)) ...

container.Register(Component.For(t).Named(t.FullName)).LifeStyle.Is(LifestyleType.Transient));

...the VS Intellisense will not kick in. 

Lifestyle doesn't belong to container.Register, Lifestyle belongs to  Component.For.Named.  This is the correct code, just remove the extra close parenthesis on Named:

container.Register(Component.For(t).Named(t.FullName).LifeStyle.Is(LifestyleType.Transient));