Cool.  Thanks.  Just ended up making my own factory (I know, goes
against the purpose of the Typed Factory Facility), but I needed the
flexibility of the anonymous type:

public class WindsorViewFactory : IViewFactory
{
        private readonly IWindsorContainer container;

        public WindsorViewFactory(IWindsorContainer container)
        {
                this.container = container;
        }

        public T CreateView<T>() where T : IView
        {
                return container.Resolve<T>();
        }

        public T CreateView<T>(object argumentsAsAnonymousType) where T : IView
        {
                return container.Resolve<T>(argumentsAsAnonymousType);
        }
}

---
Patrick Steele
http://weblogs.asp.net/psteele



2011/6/3 Krzysztof Koźmic <[email protected]>:
> Yes, custom selector is the way to go if you want to use the anonymous type,
> and Arguments class.
>
> sent from my Android
>
> On 03/06/2011 9:04 PM, Patrick Steele wrote:
>>
>> Ah, ok.  I can't use the anonymous type like I can with container.Resolve?
>>
>> I wonder if I could accomplish the anonymous types with a custom
>> ITypedFactoryComponentSelector and some reflection?
>>
>> ---
>> Patrick Steele
>> http://weblogs.asp.net/psteele
>>
>>
>>
>> 2011/6/3 Krzysztof Koźmic<[email protected]>:
>>>
>>> you need
>>>
>>>        T CreateView<T>(string arg1) where T : IView;
>>>
>>>
>>>
>>>
>>>
>>> On 03/06/2011 8:47 PM, Patrick Steele wrote:
>>>>
>>>> I'm using Windsor and I've got a spot where I'm calling
>>>> container.Resolve() directly.  Yes, bad, I know and I'm working on
>>>> fixing that but I ran into a problem and I'm wondering if I'm doing
>>>> something wrong.
>>>>
>>>> I have some code that does the basic:
>>>>
>>>> container.Resolve<TheType>();
>>>>
>>>> But there's some spots where I need to pass extra data to the ctor and
>>>> that data is not a dependency that is registered in Windsor.  I do
>>>> that via:
>>>>
>>>> container.Resolve<OtherType>(new { arg1 = "Yeah"});
>>>>
>>>> As part of my work to remove direct access to the Windsor container, I
>>>> created a factory interface that basically did those two types of
>>>> calls:
>>>>
>>>> public interface IViewFactory
>>>> {
>>>>        T CreateView<T>() where T : IView;
>>>>        T CreateView<T>(object argumentsAsAnonymousType) where T : IView;
>>>> }
>>>>
>>>> And I registered this interface with the TypedFactoryFacility (very
>>>> cool, BTW!) My calls to:
>>>>
>>>> factory.CreateView<TheType>();
>>>>
>>>> work fine.  But if I try and use the other method (with anonymous type
>>>> to pass additional constructor data):
>>>>
>>>> factory.CreateView<OtherType>(new { arg1 = "Yeah"});
>>>>
>>>> I get an exception from Windsor saying the non-optional dependency
>>>> arg1  could not be resolved.
>>>>
>>>> Should this work?  I'm using Windsor 2.5.1 from NuGet.  Thanks.
>>>>
>>>> ---
>>>> Patrick Steele
>>>> http://weblogs.asp.net/psteele
>>>>
>>> --
>>> 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.
>>>
>>>
>
> --
> 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.
>
>

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