• 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

  • 相关阅读:
    特性标签的灵活使用
    算法实例题
    网络抓包工具
    vs2010
    .NET Remoting vs Web Service
    电子商务网站设计学习
    EXCEL导出
    C# 16进制与字符串、字节数组之间的转换
    DES加密
    DataGridView生成CSV,XML 和 EXCEL文件
  • 原文地址:https://www.cnblogs.com/hellolong/p/6242502.html
Copyright © 2020-2023  润新知