ipjohnson / Grace

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

Support for removing Exports from Container #83

Closed darkcamper closed 7 years ago

darkcamper commented 7 years ago

Hi @ipjohnson , I'm looking for some kind of replacement for Ninject's Rebind functionality. It allows to throw away all the previous Exports for a certain type without modifying Exports for the rest of the types.

I'm trying to load a series of IConfigurationModule-like classes (inside a single .Configure call) that add exports to a certain interface, so I can do a Locate<IEnumerable> to retrieve them all. But sometimes I would need that a module could erase all previous exports for IThatCertainInterface before adding its own exports.

Is it currently possible with Grace? Thanks!

ipjohnson commented 7 years ago

Hi @darkcamper Currently it's not possible, that said if it's all within one configuration call I think it would be very possible. I think this would dove tail in with issue #44

I have one other thing I'm going to try and get working this weekend and then release 6.1.0. This issue and #44 would go into the next release. I probably won't get much time to address this till the following week as we have family in town for our baby shower this weekend.

darkcamper commented 7 years ago

@ipjohnson Family comes first! I'll be looking forward to testing next release. Have a nice weekend!

ipjohnson commented 7 years ago

@darkcamper I'm looking to add these two methods to the registration block interface. Let me know what you think or if you want any changes

        /// <summary>
        /// Test if a type is exported
        /// </summary>
        /// <param name="type"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        bool IsExported(Type type, object key = null);

        /// <summary>
        /// Clears exports from registration block
        /// </summary>
        /// <param name="exportFilter"></param>
        /// <returns></returns>
        bool ClearExports(Func<ICompiledExportStrategy, bool> exportFilter = null);
darkcamper commented 7 years ago

@ipjohnson I like it. I think the filter delegate solution allows you to remove whatever you want without exposing too much from the internals.