public void RegisterDelegate() { ///创建注册器 IDependencyRegister register = container.CreateRegister(); ///注册委托 register.RegisterDelegate <IUserRepository, UserRepository>(resolver => new UserRepository()); ///创建解析器 using (IDependencyResolver resolver = container.CreateResolver()) { IUserRepository userRepository = resolver.Resolve <IUserRepository>(); Assert.IsNotNull(userRepository); Assert.IsInstanceOfType(userRepository, typeof(IUserRepository)); } }