so make it dependand on a factory, say
interface IRequestedUrlProvider
{
  string GetRequestedUrl();
}

public class DefaultRequestedUrlProvider : IRequestedUrlProvider
{
  public string GetRequestedUrl() { return HttpContext.Current.Request.Url;
}
}

public class ForTestingRequestedUrlProvider : IRequestedUrlProvider
{
  public string GetRequestedUrl() { return "WHATEVER"; }
}



On Thu, Mar 5, 2009 at 1:52 PM, Henning <[email protected]>wrote:

>
> :) ok, I get it. So in my resolver I in turn ask the context - but
> this will not work in UnitTests (NUnit), since there exists noch
> HttpContext.
>
> On 5 Mrz., 12:38, Ken Egozi <[email protected]> wrote:
> > so just ask HttpContext.Current.WHADEVER
> >
> > On Thu, Mar 5, 2009 at 1:37 PM, Henning <[email protected]
> >wrote:
> - Show quoted text -
> >
> >
> >
> >
> >
> > > Ahh - I just figured, the IEngineContext is part of MonoRail, but I'm
> > > not using MonoRail. I just use the IoC capabilities of castle windsor,
> > > since my app is going to run inside of MOSS :) So I suppose I cannot
> > > use the approache you described - at least not in this way.
> >
> > > On 5 Mrz., 10:47, Ken Egozi <[email protected]> wrote:
> > > > what about adding the resolver itself to the container, and add a
> > > dependency
> > > > on IEngineContext, and setting the FactoryFacility to inject the
> current
> > > > context when asked for.
> > > > then your resolver can look at context.Request[WHATEVER] and resolev
> the
> > > > correct service
> >
> > > > On Thu, Mar 5, 2009 at 11:38 AM, Henning <
> [email protected]
> > > >wrote:
> > > - Show quoted text -
> >
> > > > > OK, so I quickly wrote a little Resolver (hey - I'm impressed, this
> > > > > was actually much easier than I first thought! Thanx to Tuna and
> > > > >http://tunatoksoz.com/post/Castle-ServiceIdResolver.aspx).
> >
> > > > > So my current setup is, that I have a singleton instance of the
> > > > > container globally available in my app. In the ctor of the
> singleton I
> > > > > do all the configuration, like registering components. I already
> > > > > figured, that I have to first register the Resolver before
> registering
> > > > > any components. But at this point in time I don't know the actual
> > > > > values I want to supply via the resolver.
> >
> > > > > So I need to access the resolver a little bit later in my app and
> set
> > > > > some properties - obviously before resolving any components via
> > > > > castle. But how do I get a handle of the resolver-instance?
> >
> > > > > On 4 Mrz., 23:39, Ayende Rahien <[email protected]> wrote:
> > > > > > Yep, you need a resolver for this.check ISubDependencyResolver
> for
> > > the
> > > > > > details.
> >
> > > > > > On Wed, Mar 4, 2009 at 2:35 PM, Henning <
> > > [email protected]
> > > > > >wrote:
> > > > > - Show quoted text -
> >
> > > > > > > hmm OK - and how ould I do something like that?
> >
> > > > > > > I assume I have to write my own resolver, which can inject this
> > > > > > > parameter to my component? If I'm adding such a resolver to my
> > > > > > > container, I still will have to tell the resolve the actual
> value
> > > to
> > > > > > > inject.
> >
> > > > > > > I didn't mention it, because I don't know if it does matter -
> this
> > > is
> > > > > > > a web-based app, and the "itemId" depends on the request being
> > > served
> > > > > > > - so the container is most likely only once initialized and
> then
> > > never
> > > > > > > again :)
> >
> > > > > > > On 4 Mrz., 23:28, Ayende Rahien <[email protected]> wrote:
> > > > > > > > if you have just global stuff, you can use a sub resolver to
> > > handle
> > > > > that
> >
> > > > > > > > On Wed, Mar 4, 2009 at 1:57 PM, Henning <
> > > > > [email protected]
> > > > > > > >wrote:
> >
> > > > > > > > > Hi,
> >
> > > > > > > > > I have an interesting problem. I have a whole bunch of
> > > components,
> > > > > > > > > which are registered in my castle container. I
> mass-registered
> > > them
> > > > > > > > > either based on a certain naming convention or on a common
> > > base-
> > > > > > > > > interface they implement. This allows me to register all my
> > > > > components
> > > > > > > > > with just two lines of code (kinda) using the fluent API.
> >
> > > > > > > > > So next I build my app using all those nice available
> > > components.
> > > > > So
> > > > > > > > > each components specifies their needs as
> > > constructor-parameters. So
> > > > > > > > > now I'm accessing only a handful of components directly in
> my
> > > app,
> > > > > > > > > everything else is magically handled by castle.
> >
> > > > > > > > > OK, so now comes the catch. I have a component
> > > > > ConfigurationContext,
> > > > > > > > > which needs an itemId parameter. This needs to be supplied
> by
> > > the
> > > > > app,
> > > > > > > > > but the component is not resolved by the app, but by the
> > > > > dependencies
> > > > > > > > > of other components.
> >
> > > > > > > > > So I would like to go ahead an tell castle "hey, is anyone
> > > needs
> > > > > the
> > > > > > > > > itemId; it's 42!".
> >
> > > > > > > > > I though this must be achievable by using properties. I
> > > remembered
> > > > > > > > > back when working with windsor.config.xml I could pass
> > > parameters
> > > > > to a
> > > > > > > > > component while referencing a property. This was also
> specified
> > > in
> > > > > the
> > > > > > > > > config-file, but hey, couldn't that be done via code as
> well?
> > > So
> > > > > this
> > > > > > > > > is the real question: how would I do something like that?
> So
> > > how
> > > > > could
> > > > > > > > > I tell the castle container that the value of a property
> called
> > > > > > > > > "itemId" is 42?
> >
> > > > > > > > > And by the way: since I mass-registered all my components I
> > > would
> > > > > need
> > > > > > > > > to adjust the ConfigurationContext component, so that
> castle
> > > know
> > > > > to
> > > > > > > > > pull the "itemId" property as a paramter for this
> component. If
> > > I
> > > > > > > > > would register this component individually I would do
> something
> > > > > like:
> >
> > > > > > > > > Container.Register(Component.For<IConfigurationContext>
> >
> > > > >
> ().ImplementedBy<ConfigurationContext>().Parameters(Parameter.ForKey
> > > > > > > > > ("ItemId").Eq("{itemId}")));
> >
> > > > > > > > > So is there any way to "modify" an existing
> > > > > component-registration?-
> > > > > > > Zitierten Text ausblenden -
> >
> > > > > > > > - Zitierten Text anzeigen -
> >
> > > > --
> > > > Ken Egozi.
> > >http://www.kenegozi.com/bloghttp://www.delver.comhttp://www.musicglue.
> ..
> >
> > --
> > Ken Egozi.
> http://www.kenegozi.com/bloghttp://www.delver.comhttp://www.musicglue.comhttp://www.castleproject.orghttp://www.gotfriends.co.il
> >
>


-- 
Ken Egozi.
http://www.kenegozi.com/blog
http://www.delver.com
http://www.musicglue.com
http://www.castleproject.org
http://www.gotfriends.co.il

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