依赖注入可以使得我们的代码变得更加良好,扩展性更强。
// 依赖注入 var builder = new ContainerBuilder(); builder.RegisterType<VolunteerFactory>().As<ILeifengFactory>(); builder.RegisterType<SqlServerFactory>().As<IDbFactory>(); var container = builder.Build(); var leifengFactory = container.Resolve<ILeifengFactory>(); var volunteer = leifengFactory.CreateLeifeng(); volunteer.Wash(); var dbFactory = container.Resolve<IDbFactory>(); dbFactory.CreateDepartmentRepo().CreateDepartment(null); Referencehttps://github.com/WeihanLi/DesignPatterns/blob/master/CreatePattern/SimpleFactoryPattern
https://github.com/WeihanLi/DesignPatterns/tree/master/CreatePattern/AbstractFactoryPattern
https://github.com/WeihanLi/DesignPatterns/blob/master/CreatePattern/FactoryMethodPattern