/// <summary> /// 构造函数; /// </summary> public frm_LogIn() { InitializeComponent(); this.StartPosition = FormStartPosition.CenterScreen; this.UserBll = new UserBll(); this.txb_UserNo.Validating += this.ValidateUserNo; this.txb_Password.Validating += this.ValidatePassword; this.ErrorProvider.BlinkRate = 500; this.AcceptButton = this.btn_LogIn; }
public MemberBll(Context context, IRepository <MembersEntity> repositoryMembers, IRepository <UserEntity> repositoryUser, IUserBll userBll) { _context = context; _repositoryMembers = repositoryMembers; _repositoryUser = repositoryUser; _userBll = userBll; }
public ReservationController(IAbsenceBll absenceBll, IReservationBll reservationBll, IUserBll userBll, IFloorBll floorBll, IBuildingBll buildingBll, IDepartmentBll departmentBll, IFlexDeskBll flexDeskBll) { this.absenceBll = absenceBll; this.reservationBll = reservationBll; this.userBll = userBll; this.buildingBll = buildingBll; this.floorBll = floorBll; this.departmentBll = departmentBll; this.flexDeskBll = flexDeskBll; this.rvm = new ReservationViewModel(); }
public ViewChangePassword(IUserBll userBll, ILoginCfgBll loginCfgBll, IGlobalApplicationData globalApplicationData) { InitializeComponent(); _userBll = userBll; _loginCfgBll = loginCfgBll; _globalApplicationData = globalApplicationData; sbtnOk.Click += sbtnOk_Click; RemoveErrorOnControlFocused(stbOldPassword, stbOldPassword.SkinTxt, errorProvider); RemoveErrorOnControlFocused(stbNewPassword, stbNewPassword.SkinTxt, errorProvider); RemoveErrorOnControlFocused(stbConfirmNewPassword, stbConfirmNewPassword.SkinTxt, errorProvider); }
public static void Run() { Console.WriteLine($"开始运行{nameof(Demo1)}"); ContainerBuilder cb = new ContainerBuilder(); cb.RegisterType <UserDal>().As <IUserDal>(); cb.RegisterType <UserBll>().As <IUserBll>(); cb.RegisterType <ConsoleSmsSender>().As <ISmsSender>(); IContainer container = cb.Build(); IUserBll userBll = container.Resolve <IUserBll>(); bool login = userBll.Login("12345678901", "Password"); Console.WriteLine(login); login = userBll.Login("10987654321", "ytrewq"); Console.WriteLine(login); Console.WriteLine($"结束运行{nameof(Demo1)}"); }
//使用ICO AutoFac static void AutoFac() { ContainerBuilder bulider = new ContainerBuilder(); //bulider.RegisterType<UserBll>().AsImplementedInterfaces();// // bulider.RegisterType<DogBll>().AsImplementedInterfaces();// Assembly asm = Assembly.Load("MyBLLImpl"); //加载这个类库中类 bulider.RegisterAssemblyTypes(asm).AsImplementedInterfaces(); // var container = bulider.Build(); IUserBll bll = container.Resolve <IUserBll>(); bll.Addone("aaa", "23"); IDogBll dogbll = container.Resolve <IDogBll>(); dogbll.Bark(); }
//一个实现类实现了多个接口 private static void UseAutoFac2() { ContainerBuilder builder = new ContainerBuilder(); //MasterBll实现了多个接口,我们可以把该类注册给他所有实现的接口 //换言之,只要是MasterBll实现的接口,我们都可以该他一个MasterBll类型的对象 //但是注意,这个MasterBll对象只包含当前接口的方法 builder.RegisterType <MasterBll>().AsImplementedInterfaces();//把MasterBll类注册给所有他实现的接口 //即一个组件暴露了多个服务,这里就等价于: //builder.RegisterType<MasterBll>().As<IUserBll>().As<IMasterBll>(); IContainer container = builder.Build(); IUserBll userBll = container.Resolve <IUserBll>(); //其实这里的userBll是MasterBll类型的对象,但是只具有IUserBll接口中的方法 userBll.Login("shanzm", "11111"); //打印:登录用户是Master:shanzm Console.WriteLine(userBll.GetType()); //打印:TestBLLImpl.MasterBll }
/// <summary> /// 构造函数; /// </summary> public frm_LogIn() { InitializeComponent(); this.StartPosition = FormStartPosition.CenterScreen; this.UserBll = new UserBll(); this.txb_UserNo.Tag = "用户号"; this.txb_Password.Tag = "密码"; this.ValidatorComponent .Add <RequiredInfoValidator> (v => v.For(this.txb_UserNo, this.txb_Password)) .Add <LengthValidator> (v => v.For(txb_UserNo) .Between(this.UserBll.UserNoMinLength, this.UserBll.UserNoMaxLength), v => v.For(txb_Password) .Between(this.UserBll.PasswordMinLengh, this.UserBll.PasswordMaxLengh)) .Add <ExistValidator> (v => v.For(txb_UserNo) .By(this.UserBll.CheckExist) .ShowErrorIfNotExist()); this.AcceptButton = this.btn_LogIn; }
public static void Show() { User user = new User() { Name = "张三", Password = "******" }; #region 引入Unity容器,这是一段固定写法 作用是读取当前应用程序运行目录下的Unity.Config配置文件,配置一个容器 //1. 初始化UnityContainer容器 IUnityContainer container = new UnityContainer(); ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); //2. 开始读取配置文件 fileMap.ExeConfigFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "CfgFiles\\Unity.Config"); Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); UnityConfigurationSection configSection = (UnityConfigurationSection)configuration.GetSection(UnityConfigurationSection.SectionName); //3.初始化AOP容器 使用配置文件中aopContainer节点下的所有配置信息来初始化container这个AOP容器 configSection.Configure(container, "aopContainer"); //10. 这个aopContainer就是配置文件中的 <container name="aopContainer"> 这里这个容器的名称 ; 注意如果配置文件中的名字和这里的名字不一样就会报出以下错误: // The container named "aopContainer" is not defined in this configuration section. #endregion // 在这里创建对象, 创建的规则就来自于配置文件的 <register type="MyAOP.UnityWay.IUserProcessor,MyAOP" mapTo="MyAOP.UnityWay.UserProcessor,MyAOP"> 这一行; 如果是 IUserProcessor 类型, 就是使用UserProcessor 来创建实例 // < !--04 核心代码 把某一个抽象类型(PrismUnityAop.BLL.IUserBll),所在的DLL(EXE名称),mapTo = (把这个接口映射到完整的类型上)-- > // < !--IOC容器所做的事情正常情况就是把某一个接口映射到具体类型-- > //01 通过容器创建对象 IUserBll processor = container.Resolve <IUserBll>(); //02 调用业务方法 正常情况应该是执行业务方法,但是我们设置了AOP所以会按照Unity配置文件中InterfaceInterceptor的顺序运行 所以是LogBeforeBehavior //02 所以是在LogBeforeBehavior,里的 public IMethodReturn Invoke方法 processor.RegUser(user); //4. 注意, 当程序运行到这里的时候, 正常情况应该是去调用userProcessor的Reguser方法, 但是由于在配置文件中进行了配置, 所以它会去执行 LogBeforeBehavior 的 Invoke的方法(当aopContainer这容器中只有一个LogBeforeBehavior的时候, 如果多个, 则那个方法在前面则优先执行, 其它的上依次的调) User userNew1 = processor.GetUser(user); //调用GetUser的时候, 也会执行配置文件中对应配置了的方法 //演示缓存Behavior User userNew2 = processor.GetUser(user); }
//把所有的接口实现类都注册 private static void UseAutoFac3() { //从上面几个示例,你可以发现好像使用依赖反转,好像有点麻烦! //若是TestBLL中有许多类,需要注册,则就可以显示出使用控制反转的 ContainerBuilder builder = new ContainerBuilder(); Assembly asm = Assembly.Load(" TestBLLImpl"); //把TestBLLImpl程序集中的所有类都是注册给他的接口 builder.RegisterAssemblyTypes(asm).AsImplementedInterfaces(); //注意RegisterAssemblyTypes()的参数可以是多个程序集 IContainer container = builder.Build(); //其实到这里你就会发现使用AutoFac的便利了, //你需要在TestIBLL项目中给定义每个接口,在TestBllImpl项目中去实现每个接口 //在TestUI项目中就不需要像以前一样去实例每一个TestBLLImpl项目中的类,使用AutoFac把每个类注册给他的接口 //然后直接调用接口对象就可以了,而且你都不用明白到底是哪个一个类实现该接口 //从而实现了解耦 IUserBll userBll = container.Resolve <IUserBll>(); userBll.Login("shanzm", "123456"); Console.WriteLine(userBll.GetType());//调试时查看uerBll接口对象中的具体实现对象:TestBllImpl.UserBll }
public static void Run() { Console.WriteLine($"开始运行{nameof(Demo2)}"); ContainerBuilder cb = new ContainerBuilder(); cb.RegisterType <UserDal>().As <IUserDal>(); cb.RegisterType <UserBll>().As <IUserBll>(); // 使用预编译命令,使得 Release 和 Debug 版本注册的对象不同,从而实现调用的短信API不同 #if DEBUG cb.RegisterType <ConsoleSmsSender>().As <ISmsSender>(); #else cb.RegisterType <HttpApiSmsSender>().As <ISmsSender>(); #endif IContainer container = cb.Build(); IUserBll userBll = container.Resolve <IUserBll>(); bool login = userBll.Login("12345678901", "Password"); Console.WriteLine(login); login = userBll.Login("10987654321", "ytrewq"); Console.WriteLine(login); Console.WriteLine($"结束运行{nameof(Demo2)}"); }
private static void UseAutoFac7() { ContainerBuilder builder = new ContainerBuilder(); Assembly asm = Assembly.Load(" TestBLLImpl"); //这里通过使用SingleInstance()实现注册给接口的实现类的对象以单例模式 builder.RegisterAssemblyTypes(asm).AsImplementedInterfaces().SingleInstance(); IContainer container = builder.Build(); using (var scope1 = container.BeginLifetimeScope()) { IUserBll userBll1 = scope1.Resolve <IUserBll>(); userBll1.Login("shanzm", "1111"); using (var scope2 = container.BeginLifetimeScope()) { IUserBll userBll2 = scope2.Resolve <IUserBll>(); userBll2.Login("shanzm", "2222"); Console.WriteLine(ReferenceEquals(userBll1, userBll2)); //因为是单一实例,所以就是在不同的生命周期中,也是同一个实例,打印结果:true } } }
public static void Run() { Console.WriteLine($"开始运行{nameof(Demo3)}"); ContainerBuilder cb = new ContainerBuilder(); cb.RegisterType <UserDal>().As <IUserDal>(); cb.RegisterType <UserBll>().As <IUserBll>(); cb.RegisterType <SmsSenderFactory>().As <ISmsSenderFactory>(); cb.RegisterType <ConfigProvider>().As <IConfigProvider>(); // The default value for enum in register is the first enum. Here is Console //cb.RegisterType<SmsConfig>().As<SmsConfig>(); // This kind of writing is better than reading directly through the configuration in the class. // More flexible... /* * Note: * I think in this case, ContainerBuilder cannot register an enum instance. * So we can only register the SmsConfig instance. */ cb.RegisterInstance(new SmsConfig { SmsSenderType = SmsSenderType.Console }).As <SmsConfig>(); IContainer container = cb.Build(); IUserBll userBll = container.Resolve <IUserBll>(); bool login = userBll.Login("12345678901", "Password"); Console.WriteLine(login); login = userBll.Login("10987654321", "ytrewq"); Console.WriteLine(login); Console.WriteLine($"结束运行{nameof(Demo3)}"); }
public AccountController(IUserBll userBll) { _userBll = userBll; }
public UserController(IUserBll userBll) { _userBll = userBll; }
/// <summary> /// Initializes a new instance of the <see cref="UsersController"/> class. /// </summary> /// <param name="userBll">User services.</param> /// <param name="localizer">Localizer services.</param> public UsersController(IUserBll userBll, IStringLocalizer <SharedResources> localizer) { this.userBll = userBll; this.localizer = localizer; }
public ArticleController(IArticleBll <T> articleBll, IUserBll userBll, IMapper mapper) : base(userBll) { _articleBll = articleBll; Mapper = mapper; }
public UserController(IUserBll userBll, IPermissionBll permissionBll, ILoginHistoryBll loginHistoryBll) { _userBll = userBll; _permissionBll = permissionBll; _loginHistoryBll = loginHistoryBll; }
public FloorController(IFloorBll floorBll, IUserBll userBll) { this.floorBll = floorBll; this.userBll = userBll; }
public GoldCalculator(IUserSubAccountBll subAccountBll, IUserBll userBll, IHangUpTimeBll hangUpTimeBll) { _subAccountBll = subAccountBll; _userBll = userBll; _hangUpTimeBll = hangUpTimeBll; _creator = userId => { return(_subAccountBll.Count(userId)); }; _timer = new Timer(obj => { if (InterlockedEx.IfThen(ref _isExecuted, 1, 1)) { return; } Interlocked.Increment(ref _isExecuted); try { foreach (var sessionId in Global.GetConnectedClientUserId()) { if (sessionId.LastCalcTime.Value.AddMinutes(10) <= DateTime.Now) { _hangUpTimeBll.Add(new HangUpTime { UserId = sessionId.Id, Minutes = 10 }); var count = CacheManager.GetSubAccountCount(sessionId.Id, _creator); int gold = 0; if (count == 1) { gold = 5; } else if (count == 2) { gold = 8; } else if (count >= 3) { gold = 13; } if (gold != 0) { _userBll.UpdateGold(sessionId.Id, gold); } sessionId.LastCalcTime = sessionId.LastCalcTime.Value.AddMinutes(10); } } } catch (Exception ex) { Global.Resolve <ILoggerFactory>() .GetCurrentClassLogger() .ErrorException("GoldCalculator Timer Callback.", ex); } finally { Interlocked.Decrement(ref _isExecuted); } }, null, Timeout.Infinite, CalculatePeriod); }
public LoginForm() { InitializeComponent(); _userBll = new UserBll(); }
public AuthenticationBll(IUserBll user) { _users = user; }
public BuildingController(IBuildingBll buildingBll, IFloorBll floorBll, IUserBll userBll) { this.buildingBll = buildingBll; this.floorBll = floorBll; this.userBll = userBll; }
public UserSettingForm() { InitializeComponent(); _userBll = new UserBll(); }
public AccountsController(IUserBll userBll, ISecurityQuestionBll securityQuestionBll, AuthenticationHelper authenticationHandler) { _userBll = userBll; _authenticationHandler = authenticationHandler; _securityQuestionBll = securityQuestionBll; }
public UserController(IUserBll userBll, IMapper mapper) { _userBll = userBll; _mapper = mapper; }
public UserMessageFilter(IUserBll userBll, IOnlineCheckBll onlineCheckBll) { _userBll = userBll; _onlineCheckBll = onlineCheckBll; }
public Provider() { _logger = DependencyResolver.Logger; _userBll = DependencyResolver.UserBll; }
public UserController(IUserBll iUserBll) { this.iUserBll = iUserBll; }
protected BikePortalController(IUserBll userBll) { UserBll = userBll; }
public LoginController(IResourceBll resourceBll, IUserBll userBll, IRoleBll roleBll) { _resourceBll = resourceBll; _userBll = userBll; _roleBll = roleBll; }
public UsersController(IUserBll userBll, IWebHostEnvironment webHostEnvironment, IFileManagementHelper fileUploadHelper) { _userBll = userBll; _webHostEnvironment = webHostEnvironment; _fileUploadHelper = fileUploadHelper; }
public AccountController(IUserBll userBll, ILoginHistoryBll loginHistoryBll) { _userBll = userBll; _loginHistoryBll = loginHistoryBll; }