ipjohnson / Grace

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

Add lifestyles for concrete types #77

Closed ipjohnson closed 7 years ago

ipjohnson commented 7 years ago

Currently all concrete types that are auto registered by the container are assumed to be transient. It would be nice to be able to provide a Func<Type,ICompiledLifeStyle> delegate that allows the user to provide lifestyles for concrete types.

An example implementation could be

public static ICompiledLifeStyle SingletonLifeStylePicker(Type type)
{
   return type.Name.EndsWith("Singleton") ? new SingletonLifeStyle() : null;
}

var container = new DependencyInjectionContainer(c => c.ConcreteLifeStylePicker = SingletonLifeStylePicker);