Mark,
It looks like you want to perform service overrides. In this case, you
might try
kernel.Register(Component.For<IService>()
.ImplementedBy<Service1>().Named("service1");
kernel.Register(Component.For<IService>()
.ImplementedBy<Service2>().Named("service2");
kernel.Register(Component.For<SomeClass>()
ServiceOverrides(
ServiceOverride.ForKey("services", "service1",
"service2")
)
);
Howerver, a more automated approach would use Hammett ISubDependencyResolver
approach
http://hammett.castleproject.org/?p=257
On Mon, Oct 6, 2008 at 8:49 AM, Mark Jensen <[EMAIL PROTECTED]> wrote:
>
> yeah, but I cant really seem to understand this new way of doing it :(
>
> So i have put toghter a small example from the link to
> CodeBetter.com... So i might better understand it
>
> What needs to be done?
>
> public interface IService
> {
> string DoSomething();
> }
>
> public class Service1 : ISerivce
> {
> }
>
> public class Service2 : ISerivce
> {
> }
>
> public class SomeClass
> {
> private IService[] services;
>
> public SomeClass(ISerivce[] services)
> {
> this.services = services;
> }
>
> public DoSomething()
> {
> // find the right service
> serivce.DoSomething();
> }
> }
>
>
> kernel.Register(Component.For<IService>()
> .ImplementedBy<Serivce1,
> Service2>()
> .DependsOn(????)
> );
>
>
> On Oct 6, 3:34 pm, "Craig Neuwirt" <[EMAIL PROTECTED]> wrote:
> > Ok, you can just use a regular dictionary then
> >
> > Hashtable config = new Hashtable();
> > config.Add("someArray", new string []{ "a", "b","c" });
> >
> > On Mon, Oct 6, 2008 at 8:16 AM, Mark Jensen <[EMAIL PROTECTED]> wrote:
> >
> > > thanks Ken
> >
> > > Anyway, Craig.. this part here: new { someArray = new []{ "a", "b",
> > > "c" }} seems to a .Net 3.0 feature? (Im using 2.0)
> >
> > > On Oct 6, 2:56 pm, "Craig Neuwirt" <[EMAIL PROTECTED]> wrote:
> > > > Mark,
> >
> > > > That example uses an older approach to registration. You might
> want to
> > > > try the fluent interface which give you more control. If not, you
> need
> > > to
> > > > register your component as you are doing and the do a
> > > > kernel.RegisterCustomDependencies("component name", new { someArray =
> new
> > > []
> > > > { "a", "b", "c" })
> >
> > > > On Mon, Oct 6, 2008 at 7:41 AM, Mark Jensen <[EMAIL PROTECTED]>
> wrote:
> >
> > > > > hmm.. maybe.. But i dont have any methods on Component?
> >
> > > > > atm i trying to make a working example from this here
> >
> > > > >
> http://dotnetslackers.com/articles/designpatterns/InversionOfControlA.
> > > ..
> >
> > > > > # IKernel kernel = new DefaultKernel();
> > > > > #
> > > > > # kernel.AddComponent("HttpFileDownloader",
> typeof(IFileDownloader),
> > > > > typeof(HttpFileDownloader));
> > > > > # kernel.AddComponent("StringParsingTitleScraper",
> > > > > typeof(ITitleScraper), typeof(StringParsingTitleScraper));
> > > > > # kernel.AddComponent("HtmlTitleRetriever",
> > > > > typeof(HtmlTitleRetriever));
> > > > > #
> > > > > # HtmlTitleRetriever retriever = (HtmlTitleRetriever)
> > > > > kernel[typeof(HtmlTitleRetriever)];
> >
> > > > > On Oct 6, 2:19 pm, "Craig Neuwirt" <[EMAIL PROTECTED]> wrote:
> > > > > > Most everything in a config file can be done programatically.
> >
> > > > > > It sounds like you want to do something like
> >
> > > > > >
> kernel.Register(Component.For<IService>().ImplementBy<MyService>()
> > > > > > .DependsOn(new { someArray = new [] { "a", "b", "c" } }
> > > > > > );
> >
> > > > > > On Mon, Oct 6, 2008 at 4:42 AM, Mark Jensen <[EMAIL PROTECTED]>
> > > wrote:
> >
> > > > > > > Hi
> >
> > > > > > > I got a question about the Microkernel
> >
> > > > > > > I know that you can parse arrays when you are using a config
> file
> >
> > >http://www.castleproject.org/container/documentation/v1rc3/usersguide.
> > > > > ..
> >
> > > > > > > but i cant find a way to do the same thing with code....
> >
> > > > > > > is it even possible? .... and how could it be done, because i
> dont
> > > > > > > wont to keep these "settings" in a config file...
> >
> > > > > > > best regards,
> > > > > > > Mark j
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---