开发者

Unity implementation of the cachedrepository pattern

开发者 https://www.devze.com 2023-04-01 01:58 出处:网络
I am trying to implement the pattern as described here http://stevesmithblog.com/blog/building-a-cachedrepository-via-strategy-pattern/ but using unity (the example uses StructureMap)

I am trying to implement the pattern as described here http://stevesmithblog.com/blog/building-a-cachedrepository-via-strategy-pattern/ but using unity (the example uses StructureMap)

I am trying to replicate this code in Unity syntax

x.For&开发者_开发技巧lt;IOrganization>().Use<OrganizationCacheRepository>().Ctor<IOrganization>).Is<OrganizationRepository>();

Any ideas?


You'll want to do something like:

_container.RegisterType<IOrganization,OrganizationCacheRepository>(new Injection Constructor(new []{new ResolvedParameter<OrganizationRepository>()});

Where RegisterType registers the initial interface/type mapping and IjectionConstructor maps the paramters to be injected into the object when it is created.

We use a ResolvedParameter to tell Unity to resolve an instance from a type/interface from the container and use it as an injection parameter.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号