c语言sscanf函数的用法是什么
275
2022-11-30
DDD领域模型企业级系统Unity(五)
添加程序集:
写一个接口:
public interface IPlayer { void Play(); }
两个实现类:
public class NewPlay : IPlayer { public void Play() { MessageBox.Show("NewPlay"); } } public void Play() { MessageBox.Show("OldPlay"); }
ServiceLocator类:
public class ServiceLocator { IUnityContainer container = new UnityContainer(); public ServiceLocator() { container.RegisterType
调用:获取一个和全部
ServiceLocator servicelocator = new ServiceLocator(); var iplay = servicelocator.GetContainer().Resolve
构造函数的调用:
[InjectionConstructor] public OldPlay() { MessageBox.Show("构造函数被执行"); }
var iplay = servicelocator.GetContainer().Resolve
属性注入:
写一个类:
public class Person { public string Name { get { return "孙"; } } public int Age { get { return 32; } } }
[Dependency] public Person person { get; set; }
自动实例化
public void Play() { MessageBox.Show("OldPlay "+person.Name); }
方法调用注入:
public Person person { get; set; }public void Play() { MessageBox.Show("OldPlay"); } [InjectionMethod] public void Auto(Person person) { MessageBox.Show("注入方法 "+person.Name); }
依赖注入的原理:
添加ProductRepository的仓储:(给聚合根建立仓储)
public class ProductRepository:EFRepository
添加SalesOrderRepository的仓储:
public class SalesOrderRepository:EFRepository
添加ProductRepository的仓储:
public class ProductRepository:EFRepository
添加CustomerRepository的仓储:
public class CustomerRepository:EFRepository
定义一个实现Product领域逻辑的部分类(继承聚合根):
public partial class Product:AggreateRoot { //定义仓储的接口 private IRepository
定义一个值对象:(负责维护自己的领域逻辑和状态信息)
public abstract class ValueObject : IValueObject { public Guid Id { get { var id = Guid.NewGuid(); return id; } } } public interface IValueObject { Guid Id { get; } }
产品类别的逻辑:
public partial class ProductCategory:ValueObject { public ProductCategory(string categoryname,string description) { this.Id = base.Id; this.CategoryName = categoryname; this.Description = description; } }
地址的值对象:
///
定义一个实现Customer领域逻辑的部分类(继承聚合根):
public partial class Customer:AggreateRoot { //定义仓储接口 private IRepository
单元测试(添加引用):
单元测试:
EFRepositoryContext context = new EFRepositoryContext(); [TestMethod] public void CreateProduct() { //Product product = new Product(new ProductRepository()); ProductAppService product = new ProductAppService(); product.CreateProduct("P1", "Red", "Small", 100, 55, "C1", "T恤类产品"); product.CreateProduct("P2", "Green", "Big", 200, 40, "C2", "运动类产品"); context.Commit(); Assert.IsNotNull(product.GetProductByName("P1")); } [TestMethod] public void CreateCustomer() { Customer customer = new Customer(new CustomerRepository()); customer.CreateCustomer("sun", "13458629365", "sanxi", "sanxi", "sanxi"); context.Commit(); Assert.IsNotNull(customer.GetCustomerByName("sun")); }
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~