ฉันมักจะเขียนตัวแปลงอะแดปเตอร์สำหรับคอนเทนเนอร์ IoC ใด ๆ ซึ่งมีลักษณะเช่นนี้:
public static class Ioc
{
    public static IIocContainer Container { get; set; }
}
public interface IIocContainer 
{
    object Get(Type type);
    T Get<T>();
    T Get<T>(string name, string value);
    void Inject(object item);
    T TryGet<T>();
}
สำหรับ Ninject โดยเฉพาะคลาส Adaptor คอนกรีตจะมีลักษณะดังนี้
public class NinjectIocContainer : IIocContainer
{
    public readonly IKernel Kernel;
    public NinjectIocContainer(params INinjectModule[] modules) 
    {
        Kernel = new StandardKernel(modules);
        new AutoWirePropertyHeuristic(Kernel);
    }
    private NinjectIocContainer()
    {
        Kernel = new StandardKernel();
        Kernel.Load(AppDomain.CurrentDomain.GetAssemblies());
        new AutoWirePropertyHeuristic(Kernel);
    }
    public object Get(Type type)
    {
        try
        {
            return Kernel.Get(type);
        }
        catch (ActivationException exception)
        {
            throw new TypeNotResolvedException(exception);
        }              
    }
    public T TryGet<T>()
    {
        return Kernel.TryGet<T>();
    }
    public T Get<T>()
    {
        try
        {
            return Kernel.Get<T>();
        }
        catch (ActivationException exception)
        {
            throw new TypeNotResolvedException(exception);
        }           
    }
    public T Get<T>(string name, string value)
    {
        var result = Kernel.TryGet<T>(metadata => metadata.Has(name) &&
                     (string.Equals(metadata.Get<string>(name), value,
                                    StringComparison.InvariantCultureIgnoreCase)));
        if (Equals(result, default(T))) throw new TypeNotResolvedException(null);
            return result;
    }
    public void Inject(object item)
    {
        Kernel.Inject(item);
    }
}
เหตุผลหลักในการทำเช่นนี้คือการทำให้กรอบ IoC เป็นนามธรรมออกไปดังนั้นฉันสามารถแทนที่มันได้ทุกเมื่อ - เนื่องจากความแตกต่างระหว่างเฟรมเวิร์กโดยทั่วไปคือการกำหนดค่าแทนที่จะใช้งาน
แต่เป็นโบนัสสิ่งต่าง ๆ ก็กลายเป็นเรื่องง่ายขึ้นสำหรับการใช้กรอบ IoC ในกรอบอื่น ๆ ที่ไม่สนับสนุนโดยธรรมชาติ สำหรับ WinForms ตัวอย่างเช่นมันเป็นสองขั้นตอน:
ในวิธีการหลักของคุณเพียงยกตัวอย่างภาชนะก่อนที่จะทำอะไรอย่างอื่น
static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        try
        {
            Ioc.Container = new NinjectIocContainer( /* include modules here */ );
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MyStartupForm());
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }
}
และจากนั้นก็มีฟอร์มฐานจากรูปแบบอื่นซึ่งได้รับมาซึ่งเรียกว่า Inject บนตัวมันเอง
public IocForm : Form
{
    public IocForm() : base()
    {
        Ioc.Container.Inject(this);
    }
}
นี่เป็นการบอกวิธีแก้ปัญหาการเดินสายอัตโนมัติเพื่อพยายามฉีดคุณสมบัติทั้งหมดซ้ำในแบบฟอร์มที่เหมาะสมกับกฎที่ตั้งค่าไว้ในโมดูลของคุณ