예제 #1
0
        static void Main(string[] args)
        {
            // 註冊型別時一併指定工廠方法
            var container = new UnityContainer();
            Func<IMessageService> factoryMethod = new MessageServiceFactory().GetService;
            container.RegisterType<IMessageService>(new InjectionFactory(c => factoryMethod()));

            // 解析
            var notyManager = container.Resolve<NotificationManager2>();

            notyManager.Notify("Michael", "Hello!");
        }
예제 #2
0
        static void Main(string[] args)
        {
            // 註冊型別時一併指定工廠方法
            var container = new UnityContainer();
            Func <IMessageService> factoryMethod = new MessageServiceFactory().GetService;

            container.RegisterType <IMessageService>(new InjectionFactory(c => factoryMethod()));

            // 解析
            var notyManager = container.Resolve <NotificationManager2>();

            notyManager.Notify("Michael", "Hello!");
        }