View on GitHub

SARAFF SOFTWARE

All products / Saraff.Twain.DS / Contents

Common services

Runtime binding

namespace Saraff.Twain.DS.IoC {

    public interface IBinder {

        void Bind(Type service,object obj);

        void Bind(Type service,object obj,bool addToContainer);

        void Bind(Type service,Type obj);

        void Bind<TService>(object obj);

        void Bind<TService>(object obj,bool addToContainer);

        void Bind<TService, T>();

        void Load(Assembly assembly); // loading binds from assembly metadata
    }
}

Metadata binding

// You may declaring bindings in assembly (that your DS define).
// In this case binds will be loading automatically

// a type must be inherit from System.ComponentModel.Component
// because it's will be placed into a container
[assembly: IoC.BindService(typeof(IService1),typeof(Service1))]
[assembly: IoC.BindService(typeof(IService2),typeof(Service2))]

// Also, you can define a bindings for specific classes.
[assembly: IoC.BindService(typeof(IoC.IContextBinder<IService2,MyCustomComponent>),typeof(Service2A))]

Factory

namespace Saraff.Twain.DS.IoC {

    public interface IInstanceFactory {

        object CreateInstance(Type type, params CtorCallback[] args);

        T CreateInstance<T>(params CtorCallback[] args) where T : class;
    }

    public delegate void CtorCallback(CtorCallbackCore callback);

    public delegate void CtorCallbackCore(string name, object val);
}

Also you can see Saraff.IoC wiki