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(); }
public void Run() { _animal.Call(); _vehicle.Drive(); }
public string Quack() { return(a.Call()); }