in the first email i'm doing this:

<code>

 var ass = Assembly.Load(assemblyname);

 var type = ass.GetType(typename);

 Type openType = typeof(GenericReportDataRepository<>);

 Type actualType = openType.MakeGenericType(new Type[] { type });

 object obj = Activator.CreateInstance(actualType);

 var genrepo = Container.Resolve<GenericReportDataRepository<obj>>();

</code>

with the intention of creating an instance of
GenericReportDataRepository<T> with the generic type being
instantiated on the fly.

the GenericReportDataRepository<T> class is explained in the following email.

that is the scenario.

initially i know the type parameter to pass to
GenericReportDataRepository only as a string.


considering i have the component registered using:


<code>
   <component id="GenericReportDataRepository"
type="Ideal.Reporting.Domain.GenericReportDataRepository`1,
Ideal.Reporting.Domain"/>
</code>

is there any way to get one of these from the container - with the
type parameter being either instantiated by activator.createinstance
or by passing a string :

var repo = Container.Resolve("GenericReportDataRepository", "TypeParameter");

or something?

it's a bit hard to explain the whole thing without going into a
massive essay - let me know if that's not making sense.

w://


2009/10/31 Krzysztof Koźmic <[email protected]>:
>
> inline,
>
> Wayne Douglas wrote:
>> ok - here goes :)
>>
>> GenericReportDataRepository provides report data - the idea being that
>> it doesn't need to know where the data comes from or what shape it is.
>>
>> i have n domains - these domains have report data DTOs which when ran
>> against the following code will retrieve the data and get populated
>> from an sp:
>>
>> <code class="GenericReportDataRepository<T>">
>>
>>  public IList<T> GetReportData<T>( Hashtable parameters, string
>> spname, string appname)
>>  {
>>            string sql = string.Empty;
>>
>>             ISQLQuery sessSql = null;
>>
>>             sql = @"exec spname] ";
>>
>>             sql += GetSPParams(params);
>>
>>             sessSql =
>> sessionManager.OpenSession(sessionName).CreateSQLQuery(sql);
>>
>>             sessSql = SetSPParams(params);
>>
>>             sessSql = AddScalarValues(sessSql, typeof(T));
>>
>>             return sessSql.SetResultTransformer(new
>> AliasToBeanResultTransformer(typeof(T))).List<T>();
>>
>> }
>> </code>
>>
>> because GenericReportDataRepository only gets called with things like
>> an assembly name as string, classname as string, the list of params
>> and their values, i need to create all this on the fly.
>>
> ? I can't see any class names or assembly names in this code. Still not
> sure what it is you want to achieve
>> sessionName ties to a configured NHibernate Facility session.
>>
>> i think i may be asking for the moon on a stick with cherries and ice
>> cream - but this must be possible. i really hope so.
>>
>> w://
>>
>> 2009/10/31 Krzysztof Koźmic <[email protected]>:
>>
>>> What do you want to do?
>>>
>>> Give me actual scenario,
>>>
>>> Wayne Douglas wrote:
>>>
>>>> Hi
>>>>
>>>> if i have a component registered with :
>>>>
>>>> <code>
>>>>     <component id="GenericReportDataRepository"
>>>> type="Ideal.Reporting.Domain.GenericReportDataRepository`1,
>>>> Ideal.Reporting.Domain"/>
>>>> </code>
>>>>
>>>> is there anyway i can retrieve that by using something similar to:
>>>>
>>>> <code>
>>>>
>>>>  var ass = Assembly.Load(assemblyname);
>>>>
>>>>  var type = ass.GetType(typename);
>>>>
>>>>  Type openType = typeof(GenericReportDataRepository<>);
>>>>
>>>>  Type actualType = openType.MakeGenericType(new Type[] { type });
>>>>
>>>>  object obj = Activator.CreateInstance(actualType);
>>>>
>>>>  var genrepo = Container.Resolve<GenericReportDataRepository<obj>>();
>>>>
>>>> </code>
>>>>
>>>> I know the code sucks in terms of names and stuff - i'm just typing it
>>>> in to gmail - just trying to figure out how to do this.
>>>>
>>>> struggling a bit :)
>>>>
>>>>
>>>>
>>>
>>
>>
>>
>>
>
>
> >
>



-- 
Cheers,

w://

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