Found a solution:
container.Register(Classes.FromAssemblyContaining(typeof(IRepository))
.BasedOn<IRepository>()
.If(Component.IsInSameNamespaceAs<BaseEntityRepository<BaseEntity>>())
.If(t => t.Name.EndsWith("Repository") &&
(t.Name.StartsWith("Foo") || t.Name.StartsWith("Bar")))
.Configure(c =>
c.DependsOn(ServiceOverride.ForKey("Session").Eq("db.session.second")).DependsOn(ServiceOverride.ForKey("SessionFactory").Eq("db.sessionfactory.second"))).LifestylePerThread());
> Since Castle.Windsor was updated to 3.0.0.4001 ServiceOverrides method
> became obsolete. So I need help to rewrite my old code to new style
> with using DependsOn method.
>
> container.Register(AllTypes.FromAssemblyContaining(typeof(IRepository))
> .BasedOn<IRepository>()
> .If(Component.IsInSameNamespaceAs<BaseEntityRepository<BaseEntity>>())
> .If(t =>
> t.Name.EndsWith("Repository") &&
> (t.Name.StartsWith("Foo") || t.Name.StartsWith("Bar")))
> .Configure(c =>
>
> c.ServiceOverrides(ServiceOverride.ForKey("Session").Eq("db.session.second" ))
>
> .ServiceOverrides(ServiceOverride.ForKey("SessionFactory").Eq("db.sessionfa
> ctory.second"))
> .LifeStyle.PerThread));
> I tried to rewrote this code like this:
>
> container.Register(Component.For<IRepository>().ImplementedBy<FooRepository
> >()
> .DependsOn(new Dictionary<string, string>
> {{"Session", "db.session.second"},
> {"SessionFactory", "db.sessionfactory.second"}})
> .LifeStyle.PerThread);
>
> but got null when tried to Resolve FooRepository object. Also with
> this approach I can't override services for several components (like
> first approach with If using), so I need write individual Register
> line for each component. All other code stay same and work fine.
--
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.