Config Generic in xml file

22 views
Skip to first unread message

FrankM

unread,
Aug 8, 2008, 2:00:44 PM8/8/08
to structuremap-users
Hi there,

Maybe this question sounds weird, that's because I just started to
play structuremap since yesterday.Here is my problem,

My Repository class:

public interface : IRepository<T> { (...) }

public class UserDTO {(...) }

public class UserRepository : IRepository<UserDTO>
{ ...
}


The config file can handle this without problem.

<DefaultInstance
PluginType="MyDemo.IRepository`1, MyDemo"
PluggedType="MyDemo.UserRepository , MyDemo"
/>

But after adding a second repository class using the same pattern.
say,
public class ItemDTO {(...) }
public class ItemRepository : IRepository<ItemDTO>
{ ...
}

I got all kind of errors then, how to add this into the config file,
IRepository`2? or different syntax other than DefaultInstance?

I tried adding
StructureMapConfiguration
.ForRequestedType<IRepository<OrganizationDTO>>().TheDefaultIsConcreteType<OrganizationRepository>();

into my code and it works OK but I do want to keep all those wrapping
work into xml file.

Any feedback will be appreciated. Thanks.

Jimmy Bogard

unread,
Aug 8, 2008, 8:31:12 PM8/8/08
to structure...@googlegroups.com
This may or may not help...but I never really refer to IRepository<T> (or IMapper<T, U>, etc.) in the rest of the system.  Generics can really invade your application like a virus if you don't keep them in check.

Instead, I'll do something like this :

public interface IUserRepository : IRepository<User>

public class UserRepository : IUserRepository

Then everything needing an IRepository<User> uses the IUserRepository.  It disambiguates better, IMO.  Plus the Type.FullName of generics is frickin' nasty, where the concrete interface also keeps this in check.

In any case, the real type you'd want, generics wise is something like MyDemo.IRepository'1[[MyDemo.UserDTO]].  That's the difference between typeof(IRepository<>).FullName and typeof(IRepository<UserDTO>).FullName.

The IUserRepository is cleaner, both in configuration and usage.
Reply all
Reply to author
Forward
0 new messages