Roelof, this might work if IWriteRepository<> was only implemented by DocumentRepository. However, as I just mentioned to Belvasis, there are many implementations of IWriteRepository<>, and I would like them all to be decorated by the SecurityRepositoryDecorator.
Joni On Mar 9, 10:59 am, Roelof Blom <[email protected]> wrote: > This should work with fluent registration. > > Component.For(typeof(IWriteRepository<>)).ImplementedBy(typeof(SecurityRepositoryDecorator<>)) > > .Named("sec.repository").DependsOn(Parameter.ForKey("inner").Eq("#{doc.repository}")), > > Component.For(typeof(IWriteRepository<>)).ImplementedBy(typeof(DocumentRepository<>)) > .Named("doc.repository") > -- Roelof. > > On Mon, Mar 8, 2010 at 7:52 PM, Belvasis <[email protected]> wrote: > > since there are two IWriteRepository<T> Implementations it will not work > > with this > > configuration. Using XML it is easy to do this. I don't know the fluent API > > but > > i think there is a way to configure the key and the dependencies. So in the > > end > > and you can use > > container.Resolve<IWriteRepository<Document>>("repository"), where > > the SecurityRepositoryDecorator has the id="repository". > > In XML it would look like this > > > <component > > id="repository" > > service="Definition.IWriteRepository`1, Definition" > > type="DecoratorImpl.SecurityRepositoryDecorator`1, DecoratorImpl" > > lifestyle="transient"> > > <parameters> > > <Inner>${registry_impl}</Inner> > > </parameters> > > </component> > > <component > > id="registry_Impl" > > service="Definition.IRepository`1, Definition" > > type="NHibernateImpl.NHibernateRepository`1, NHibernateImpl" > > lifestyle="transient"> > > </component> > > > 2010/3/8 Krzysztof Koźmic <[email protected]> > > >http://stw.castleproject.org/Windsor.Decorators.ashx > >>http://ayende.com/Blog/archive/2008/10/05/windsor-ihandlerselector.aspx > > >> On 3/8/2010 6:47 PM, joniba wrote: > > >>> Hi Krzysztof, how would implementing the IHandlerSelector help me? How > >>> will I differentiate between the initial call to (continuing the > >>> example) > > >>> container.Resolve<IWriteRepository<Document>>() > > >>> With castle windsor's internal attempt to resolve the > >>> SecurityRepositoryDecorator's "inner" parameter? > > >>> Thanks > >>> Joni > > >>> On Mar 8, 7:17 pm, Krzysztof Koźmic<[email protected]> > >>> wrote: > > >>>> use IHandlerSelector > > >>>> On 3/8/2010 5:59 PM, joniba wrote: > > >>>>> Hi all, I'm trying to use Castle Windsor to implement decorator > >>>>> chains, as per Ayende's msdn post. However, I'm using the fluent API, > >>>>> and I want to know if it can be done en masse. > > >>>>> Without the decorators I have: > > >>>>> container.Register > >>>>> ( > >>>>> AllTypes.FromAssembly(assembly) > >>>>> .IncludeNonPublicTypes() > > >>>>> .BasedOn(typeof(IWriteRepository<>)).WithService.Base() > >>>>> .Configure(component => > >>>>> component.LifeStyle.Transient) > >>>>> ); > > >>>>> (Which works fine.) > >>>>> My decorators also implement IWriteRepository<T>, and take as the > >>>>> inner, an IWriteRepository<T>. For example: > > >>>>> public class SecurityRepositoryDecorator<TEntity> : > >>>>> IWriteRepository<TEntity> > >>>>> { > >>>>> private IWriteRepository<TEntity> inner; > > >>>>> public SecurityRepositoryDecorator(IWriteRepository<TEntity> > >>>>> inner) > >>>>> { > >>>>> this.inner = inner; > >>>>> } > >>>>> } > > >>>>> Is this impossible because of a circular reference to > >>>>> IWriteRepository<>? > >>>>> I would like to get to: > > >>>>> var repository = container.Resolve<IWriteRepository<Document>>(); > > >>>>> And have this return a SecurityRepositoryDecorator wrapping a > >>>>> DocumentRepository. > >>>>> Any ideas are appreciated. > > >>>>> Joni > > >> -- > >> 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]<castle-project-users%[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]<castle-project-users%[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.
