ipjohnson / Grace

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

Minify interfaces #133

Closed mcdis closed 6 years ago

mcdis commented 6 years ago

Related to https://github.com/ipjohnson/Grace/issues/131

Let's look to ILocatorService:

public interface ILocatorService
{
  //...
  T Locate<T>();
  object Locate(Type type);
}

And let's compare to implementation InjectionScope:

public class InjectionScope : ...
{
    public T Locate<T>()
    {
      return (T) this.Locate(typeof (T)); // <--call ILocatorService Locate(Type)
    }
}

So we can shrink ILocatorService, remove T Locate<T>() and replace it to extension method to ILocatorService like:

 public static class ILocatorServiceExtensions
 {
    public static T Locate<T>(this ILocatorService _this)=>(T) _this.Locate(typeof (T));
 }

LocateOrDefault and other methods can be removed from interface and start live in extension form.

So work in this way the Grace interface will stay more cleaner and smaller and lighter

ipjohnson commented 6 years ago

Just so you are aware I don't envision starting work on changing the interfaces any time soon. If it does happen it will be a year plus out as I have other things I'm interested in working on.