I was scratching my head trying to figure out how use Lifestyle and
DependsOn when they aren't members of BasedOnDescriptor when I
stumbled upon the missing piece of the puzzle:
BasedOnDescriptor.Configure()
So it should look like this:
container.Register(
AllTypes
.Of<MyInterface>
.FromAssembly(myAssembly)
.Configure(componentRegistration =>
componentRegistration.Lifestyle.Transient.DependsOn(new
{id=0,name=""}))
);
Unfortunately I'm getting an error message: "Can't create component
'MyClass' as it has dependencies to be satisfied.
- id which was not registered.
- name which was not registered.
On Dec 29, 2:48 pm, Mike Nichols <[email protected]> wrote:
> A. by default the first registered implementation will resolve without
> explicitly providing a key, or you can implement something like a
> ISubDependencyResolver for more sophistication...among other ways
> B. Lifestyle.Transient
> C. .DependsOn(new{ id = 42,name="documentation"})
>
> see herehttp://using.castleproject.org/display/IoC/Fluent+Registration+API
>
> On Dec 29, 10:52 am, ksc654 <[email protected]> wrote:
>
>
>
> > Lets say I have a class that looks like this:
>
> > public class MyClass: MyInterface
> > {
> > private int _id;
> > private string _name;
>
> > public MyClass(int id, string name)
> > {
> > _id = id;
> > _name = name;
> > }
>
> > }
>
> > I'm loading the class into a WindsorContainer along with every other
> > implementation of MyInterface like so:
>
> > container.Register(AllTypes.Of<MyInterface>.FromAssembly(myAssembly));
>
> > How do I:
> > A. Ensure the correct implementation of MyInterface is resolved
> > B. Return a new instance of MyClass each time resolve is called
> > C. Supply the container with default values for the MyClass
> > constructor
>
> > I would like to accomplish these using the fluent api if possible but
> > will fall back to xml configuration if there is no other alternative.
--
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.