ipjohnson / Grace

Grace is a feature rich dependency injection container library
MIT License
336 stars 33 forks source link

Provide extensions to make proxy location simplier #127

Closed mcdis closed 6 years ago

mcdis commented 6 years ago

Register proxy location to another container. In my case when the system is configurating some modules have to register global interfaces but part of behaviors are registered in child container. So, I need to resolve my interfaces with child container behaviors but after that I have to get acces from global. So in my case proxing is common way.

Example

mainContainer.Configure(_ => _.ExportFactory(() => otherContainer.Locate<IUiLocalizedTextProvider>()).Lifestyle.Singleton());

In my case I know that proxied IUiLocalizedTextProvider can be cached so I use .Lifestyle.Singleton()

Syntax proposal: a)

container.Configure(_=>_.Proxy<T>(otherContainer));
//.ExportFactory(() => otherContainer.Locate<T>()).Lifestyle.Singleton()

b)

container.Configure(_=>_.ProxyAndCache<T>(otherContainer)); 
// .ExportFactory(() => otherContainer.Locate<T>()).Lifestyle.Singleton()
ipjohnson commented 6 years ago

@mcdis I this seems like some what of a niche extension. For the moment I'm going to recommend implementing them as C# extensions in your code base and if I get some more requests in we can look at formalizing the code into an extension library for Grace

mcdis commented 6 years ago

ok, that's the way I'm doing now

ipjohnson commented 6 years ago

I'm going to close this and a new issue can be created if it becomes a popular request