Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //配置文件
            IAnimal cat = Init.GetService <IAnimal>("Dog", new NamedParameter("name", "小小白"));

            cat.Call();

            //普通方式
            // var builder = new ContainerBuilder();
            /// builder.RegisterType<Dog>().AsSelf().As<IAnimal>();
            //表示注册的类型,以接口的方式注册
            // IContainer container;
            // var builder = new ContainerBuilder();
            //builder.RegisterType<Dog>().AsSelf().AsImplementedInterfaces();

            //寻找只带特性的注入
            //builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies())
            //                        .Where(t => t.GetCustomAttribute<DependencyRegisterAttribute>() != null)
            //                        .AsImplementedInterfaces();
            //container = builder.Build();
            //从容器中取出一个T类型的实例
            //IAnimal a = container.Resolve<IAnimal>(new NamedParameter("name","否"));
            //a.Call();


            Console.Read();
        }
Exemplo n.º 2
0
 public void Run()
 {
     _animal.Call();
     _vehicle.Drive();
 }
Exemplo n.º 3
0
 public string Quack()
 {
     return(a.Call());
 }