servicetitan / lazy-proxy-unity Goto Github PK
View Code? Open in Web Editor NEWLazy Dependency Injection for Unity Container
License: Other
Lazy Dependency Injection for Unity Container
License: Other
Hi! Thanks for sharing, this is very useful but Unity keeps messing with NuGet. I was wondering if there are any plans to create an OpenUPM package out of it. If now, would be ok if I create it?
Hi,
I have an interface that is implemented by 2 classes. I used named instance registration:
using (IUnityContainer container = new UnityContainer())
{
container.RegisterLazy<IController, Controller>("Controller");
container.RegisterLazy<IController, MyController>("MyController");
var objs = container.ResolveAll<IController>();
foreach (IController controller in objs)
{
string s = controller.Name;
}
}
Now, the reason I get 4 implementation in the objs object is because in the Initialise method we are registering the same type with its implementation twice:
protected override void Initialize()
{
string registrationName = Guid.NewGuid().ToString();
Context.Container.RegisterType(_typeFrom, _typeTo, _name, _getLifetimeManager(), _injectionMembers);
Context.Container.RegisterType(_typeFrom, _typeTo, registrationName, _getLifetimeManager(), _injectionMembers); // this is proxy registration... which is causing me trouble --- why we need this?
Context.Policies.Set(_typeFrom, _name, typeof(ResolveDelegateFactory),
(ResolveDelegateFactory)((ref BuilderContext _) =>
(ref BuilderContext c) =>
{
IUnityContainer container = c.Container;
Type type = c.RegistrationType;
ResolverOverride[] overrides = c.Overrides;
return LazyProxyBuilder.CreateInstance(type,
//() => container.Resolve(type, registrationName, overrides)
() => container.Resolve(type, _name)
);
})
);
}
Can someone please help me understand why we have double registration for each type?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.