SimonG96 / LightweightIocContainer

A lightweight IOC Container that is powerful enough to do all the things you need it to do.
MIT License
4 stars 2 forks source link

`OnCreate()` should pass implementation not interface #34

Closed SimonG96 closed 4 years ago

SimonG96 commented 4 years ago

The OnCreate() method should not pass the registered interface to create an action:

https://github.com/SimonG96/LightweightIocContainer/blob/c25896a56e648e232076acb681773bd7f72f7e6a/LightweightIocContainer/Interfaces/Registrations/FluentProviders/IOnCreate.cs#L27

It should pass the implementation that is registered for the given interface.
This simplifies #33 because we don't need to have multiple Action<T> for an OnCreate() method.

SimonG96 commented 4 years ago

To do this, there has to be a registration (maybe ITypedRegistrationBase) that has a generic parameter TImplementation:

public interface ITypedRegistrationBase<TInterface, TImplementation> : IRegistrationBase<TInterface>, IOnCreate<TImplementation>
SimonG96 commented 4 years ago

Use a non-generic interface IOnCreate that contains an Action with parameter object:

public interface IOnCreate
{
    Action<object> NonGenericOnCreateAction { get; }
}

The generic IOnCreate<TImplementation> has to implement this non-generic interface, and the OnCreate() method has to set the new Action as well.

Maybe the IOnCreate<>.OnCreateAction could be removed and the new Action could be used.