Giter Club home page Giter Club logo

minioc's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

minioc's Issues

IDisposable on Scope doesn't call Dispose on cached instances

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);

Enable instantiable container

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?

Consider non-generic methods/IServiceProvider

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.