microsoft / minioc Goto Github PK
View Code? Open in Web Editor NEWSingle-file minimal C# IoC container
License: MIT License
Single-file minimal C# IoC container
License: MIT License
There are important files that Microsoft projects should all have that are not present in this repository. A pull request has been opened to add the missing file(s). When the pr is merged this issue will be closed automatically.
Microsoft teams can learn more about this effort and share feedback within the open source guidance available internally.
Based on reading the code; haven't tested, but I think the repro would be something like:
class SpyDisposable : IDisposable
{
public bool Disposed { get; private set; }
public void Dispose()
{
Disposed = true;
}
}
Container.Register<SpyDisposable>(typeof(SpyDisposable));
SpyDisposable spy;
using (var scope = Container.CreateScope())
{
spy = scope.Resolve<SpyDisposable>();
}
Assert.True(spy.Disposed);
There are scenarios where we would want to spin up multiple container instances (eg. registering different types against each instance).
Started exploration of this here: https://github.com/Microsoft/MinIoC/tree/container_instances
Questions to explore:
Keep static Container API or remove in favor of always requiring instantiation or provide a static singleton on the instantiable type?
If we keep static Container, what's a good name for the new type?
Would we want a singleton that is a single instance across containers, or would a singleton only be unique for a container?
Should instantiable container implement IScope?
Is there any fundamental difference anymore between a scope and a container?
Internally, I believe Container has everything as Type and object. Suppose a caller has a list of types to register and/or resolve, like this:
Type[] typesToRegister = new Type { typeof(A), typeof(B) };
foreach (Type toRegister in typesToRegister)
{
container.Register(toRegister, toRegister);
}
Currently, I believe the caller would be required to use reflection to MakeGenericMethod. What's the ideal "Min" version of the container surface area? Perhaps:
IRegisteredType Register(Type interfaceType, Type implementationType);
IRegisteredType Register(Type interfaceType, Func<object> factory);
And for resolve:
object Resolve(Type interfaceType);
Does that feel like the right "Min" set? Extension methods could be built on top to support:
Register<T>(Type type); // current form
Register<T, TImplementation>(); // generic version for the second argument
Register(Type type); // class without a separate interface
Register<T>(); // generic version of above form
Register<T>(Func<T> factory); // current form
T Resolve<T>(); // current form
Thoughts?
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.