• CastelWindsor Demo


     1  class Program
     2     {
     3         static void Main(string[] args)
     4         {
     5             var container = new WindsorContainer();
     6             container.Install(FromAssembly.This());
     7 
     8             var king = container.Resolve<IKing>("King1");
     9             king.SayHello();
    10             var king2 = container.Resolve<IKing>("King2");
    11             king2.SayHello();
    12             Console.Read();
    13 
    14         }
    15     }
    16     public class RepositoriesInstaller : IWindsorInstaller
    17     {
    18         public void Install(IWindsorContainer container, IConfigurationStore store)
    19         {
    20             //container.Register(Classes.FromThisAssembly()
    21             //                    .Where(Component.IsInSameNamespaceAs<King>())
    22             //                    .WithService.DefaultInterfaces()
    23             //                    .LifestyleTransient());
    24             //container.Register(Classes.FromThisAssembly()
    25             //                    .Where(Component.IsInSameNamespaceAs<King2>())
    26             //                    .WithService.DefaultInterfaces()
    27             //                    .LifestyleTransient());
    28             container.Register(Component.For(typeof(IKing))
    29                 .ImplementedBy(typeof(King1))
    30                 .Named("King1").LifestyleTransient());
    31             container.Register(Component.For(typeof (IKing))
    32                 .ImplementedBy(typeof (King2))
    33                 .Named("King2").LifestyleTransient());
    34         }
    35     }
    36 
    37     public interface IKing
    38     {
    39         void SayHello();
    40     }
    41 
    42     public class King1 : IKing
    43     {
    44         public void SayHello()
    45         {
    46             Console.WriteLine("Hello i am the first king1");
    47         }
    48     }
    49 
    50 
    51     public class King2 : IKing
    52     {
    53         public void SayHello()
    54         {
    55             Console.WriteLine("Hello i am the first king2");
    56         }
    57     }

    https://github.com/castleproject/Windsor/blob/master/docs/README.md

  • 相关阅读:
    判断平面的一堆点是否在两条直线上
    约数的个数 + 贪心
    划分树板子
    如何获取前端提交来得json格式数据
    post 和php://input 转
    使用Guzzle执行HTTP请求
    redis集群搭建 不用ruby
    systemctl命令
    canal 配置 多个监听 推送到不同mq
    canal 整合RabbitMQ
  • 原文地址:https://www.cnblogs.com/hellolong/p/6242502.html
Copyright © 2020-2023  润新知