Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Resolving component without registering it in container
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
ashmind  
View profile  
 More options May 27 2008, 8:13 am
From: ashmind <ashm...@gmail.com>
Date: Tue, 27 May 2008 05:13:47 -0700 (PDT)
Local: Tues, May 27 2008 8:13 am
Subject: Resolving component without registering it in container
Consider the following code:
public class MyClass {
    public MyClass(IService1 s1, IService2 s2, ...) {
    }

}

What is the easiest way to create MyClass using WindsorContainer
without adding it to the container?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ken Egozi  
View profile  
 More options May 27 2008, 8:30 am
From: "Ken Egozi" <egoz...@gmail.com>
Date: Tue, 27 May 2008 15:30:33 +0300
Local: Tues, May 27 2008 8:30 am
Subject: Re: Resolving component without registering it in container

var my = new MyClass(IoC.Resolve<IService1>(), IoC.Resolve<IService2>, ...);

On Tue, May 27, 2008 at 3:13 PM, ashmind <ashm...@gmail.com> wrote:

> Consider the following code:
> public class MyClass {
>    public MyClass(IService1 s1, IService2 s2, ...) {
>    }
> }

> What is the easiest way to create MyClass using WindsorContainer
> without adding it to the container?

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

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ashmind  
View profile  
 More options May 27 2008, 8:48 am
From: ashmind <ashm...@gmail.com>
Date: Tue, 27 May 2008 05:48:44 -0700 (PDT)
Local: Tues, May 27 2008 8:48 am
Subject: Re: Resolving component without registering it in container
Sorry, I should have said that I thought about this solution.
However, it does not benefit from having container.
What I really want is to use container constructor resolution, etc,
but for class that is not registered.

Something like var my = container.Create<MyClass>();

On 27 май, 15:30, "Ken Egozi" <egoz...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andre Loker  
View profile  
 More options May 27 2008, 9:01 am
From: Andre Loker <lo...@gmx.de>
Date: Tue, 27 May 2008 15:01:53 +0200
Local: Tues, May 27 2008 9:01 am
Subject: Re: Resolving component without registering it in container
Hi,
> Sorry, I should have said that I thought about this solution.
> However, it does not benefit from having container.
> What I really want is to use container constructor resolution, etc,
> but for class that is not registered.

> Something like var my = container.Create<MyClass>();

Is there any why you cannot register the component at the container? If
you define "Transient" as the life style any call to resolve would
create a new instance of MyClass, just as in your code example.
container.AddComponentLifeStyle<MyClass>(LifestyleType.Transient);
..
var my = container.Resolve<MyClass>();

Regards,
Andre


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ashmind  
View profile  
 More options May 27 2008, 9:09 am
From: ashmind <ashm...@gmail.com>
Date: Tue, 27 May 2008 06:09:20 -0700 (PDT)
Local: Tues, May 27 2008 9:09 am
Subject: Re: Resolving component without registering it in container
I do not want to put in the container, since it depends on other data
that makes sense only within a certain scope.
It will work inside a container, if I provide the data via
additionalArguments or other means.
But it fells like a container pollution -- putting in a class that no
other class should depend on and that can be resolved only within a
certain circumstances.

On 27 май, 16:01, Andre Loker <lo...@gmx.de> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ayende Rahien  
View profile  
 More options May 27 2008, 10:19 am
From: "Ayende Rahien" <aye...@ayende.com>
Date: Tue, 27 May 2008 17:19:46 +0300
Local: Tues, May 27 2008 10:19 am
Subject: Re: Resolving component without registering it in container

This came up several times. We had a solution that wasn't satisfactory, auto
registering in the container.
I think we need to have a solution for that.

One question, how are we going to handle caching of reflection information?

2008/5/27 ashmind <ashm...@gmail.com>:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ashmind  
View profile  
 More options May 27 2008, 10:30 am
From: ashmind <ashm...@gmail.com>
Date: Tue, 27 May 2008 07:30:30 -0700 (PDT)
Local: Tues, May 27 2008 10:30 am
Subject: Re: Resolving component without registering it in container
For my specific case, performance is unimportant.

I think the reflection data can be cached by resolved Type, but I am
not sure what criteria are for choosing caching solution.
It may be possible to overload straightforward Type-based caching by
continuosly resolving different variants of the same generic.

On 27 май, 17:19, "Ayende Rahien" <aye...@ayende.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ashmind  
View profile  
 More options May 28 2008, 9:27 am
From: ashmind <ashm...@gmail.com>
Date: Wed, 28 May 2008 06:27:58 -0700 (PDT)
Local: Wed, May 28 2008 9:27 am
Subject: Re: Resolving component without registering it in container
Simplest and slowest solution in case anybody needs it:
public static class MicroKernelExtensions {
    public static T Create<T>(this IKernel kernel) {
        return (T)kernel.Create(typeof(T));
    }

    public static object Create(this IKernel kernel, Type classType) {
        var childKernel = new DefaultKernel { Parent = kernel };
        childKernel.AddComponent(classType.Name, classType,
classType);

        return childKernel.Resolve(classType);
    }

}

This is ugly and *very* slow, 20 secs for 100000 Create vs 3 secs for
100000 Resolve for pre-registered component.
It is possible to add caching, and basic {Type => IKernel} caching
improves performance to be nearly equal to Resolve.

Since performance is not important for my case, and caching will
require good locking mechanism, I will use the above solution for now.

On 27 май, 15:13, ashmind <ashm...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ayende Rahien  
View profile  
 More options May 28 2008, 9:37 am
From: "Ayende Rahien" <aye...@ayende.com>
Date: Wed, 28 May 2008 16:37:35 +0300
Local: Wed, May 28 2008 9:37 am
Subject: Re: Resolving component without registering it in container

This is also not valid when you are creating an item that requires
dependencies from the container.

2008/5/28 ashmind <ashm...@gmail.com>:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ayende Rahien  
View profile  
 More options May 28 2008, 9:38 am
From: "Ayende Rahien" <aye...@ayende.com>
Date: Wed, 28 May 2008 16:38:22 +0300
Local: Wed, May 28 2008 9:38 am
Subject: Re: Resolving component without registering it in container

I think that the best solution would be to create a new container for all of
those, and link it as a child container to the root container.
That will allow resolving dependencies form the container.

2008/5/28 Ayende Rahien <aye...@ayende.com>:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ashmind  
View profile  
 More options May 28 2008, 12:35 pm
From: ashmind <ashm...@gmail.com>
Date: Wed, 28 May 2008 09:35:55 -0700 (PDT)
Local: Wed, May 28 2008 12:35 pm
Subject: Re: Resolving component without registering it in container

> This is also not valid when you are creating an item that requires
> dependencies from the container.

Actually, I think, { Parent = kernel } solves this.

> I think that the best solution would be to create a new container for all of
> those, and link it as a child container to the root container.

The single child container would be more performant, but components
will be able to depend on each other.
So, I think, if performance is less important, child container per
Create is better.

On May 28, 5:37 pm, "Ayende Rahien" <aye...@ayende.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »