public static void Show() { User user = new User() { Name = "caixukun", Password = "******" }; { //通过Unity实例化对象 //IUnityContainer container = new UnityContainer(); //container.RegisterType<IUserProcessor, UserProcessor>(); //IUserProcessor processor = container.Resolve<IUserProcessor>(); //processor.RegUser(user); } { //配置UnityContainer实现AOP动态代理 IUnityContainer container = new UnityContainer(); //ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); //fileMap.ExeConfigFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "CfgFiles\\Unity.Config"); //Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); //UnityConfigurationSection configSection = (UnityConfigurationSection)configuration.GetSection(UnityConfigurationSection.SectionName); UnityConfigurationSection configSection = (UnityConfigurationSection)ConfigurationManager.GetSection("unity"); configSection.Configure(container, "aopContainer"); IUserProcessor processor = container.Resolve <IUserProcessor>(); //processor.RegUser(user); Console.WriteLine(processor.GetUser(user)); Console.WriteLine(processor.GetUser(user)); } }
static void Main(string[] args) { try { IUnityContainer container = new UnityContainer(); ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "Config\\Unity.Config"); Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); UnityConfigurationSection configSection = (UnityConfigurationSection)configuration.GetSection(UnityConfigurationSection.SectionName); configSection.Configure(container, "aopContainer"); User user = new User() { Name = "Michael", MotPass = "******" }; IUserProcessor processor = container.Resolve <IUserProcessor>(); processor.RegUser(user); Console.WriteLine("-------------------------------------------"); User user1 = processor.GetUser(user); Console.WriteLine("-------------------------------------------"); User user2 = processor.GetUser(user); } catch (Exception e) { Console.WriteLine(e.Message); } finally { Console.ReadKey(); } }
public static void Show() { User user = new User() { Name = "Eleven", Password = "******" }; { IUnityContainer container = new UnityContainer(); container.RegisterType <IUserProcessor, UserProcessor>(); IUserProcessor processor = container.Resolve <IUserProcessor>(); processor.RegUser(user); } { //配置UnityContainer IUnityContainer container = new UnityContainer(); ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "CfgFiles\\Unity.Config"); Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); UnityConfigurationSection configSection = (UnityConfigurationSection)configuration.GetSection(UnityConfigurationSection.SectionName); configSection.Configure(container, "aopContainer"); IUserProcessor processor = container.Resolve <IUserProcessor>(); processor.RegUser(user); User userNew1 = processor.GetUser(user); User userNew2 = processor.GetUser(user); } }
/// <summary> /// 将委托的实例直接调用的两种方法 /// getNext().Invoke(input, getNext); /// getNext()(input, getNext); /// </summary> public static void Show() { User user = new User() { Name = "张三", Password = "******" }; { //Unity容器的基本使用 //IUnityContainer container = new UnityContainer(); //container.RegisterType<IUserProcessor, UserProcessor>(); //IUserProcessor Processor = container.Resolve<IUserProcessor>(); //Processor.RegUser(user); } { //Unity容器实现AOP //注意 : XML配置文件,右键选择属性,始终复制,可以将文件生成到bin目录下 IUnityContainer container = new UnityContainer(); // ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "config\\Unity.Config"); // Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); UnityConfigurationSection configSection = (UnityConfigurationSection)configuration.GetSection(UnityConfigurationSection.SectionName); configSection.Configure(container, "aopContainer"); IUserProcessor processor = container.Resolve <IUserProcessor>(); processor.RegUser(user); //模拟用户注册 User userNew1 = processor.GetUser(user); User userNew2 = processor.GetUser(user); } }
[AuthorizeAdmin] // TODO Do we need to allow this endpoint for students? public IActionResult GetUser([FromRoute] Guid id) { var user = _userProcessor.GetUser(id); if (user == null) { return(NoContent()); } return(Ok(user)); }
public static void Show() { User user = new User() { Name = "Eleven", Password = "******" }; { UserProcessor processor = new UserProcessor(); processor.RegUser(user); Console.WriteLine("*********************"); } { IUnityContainer container = new UnityContainer(); //声明一个容器 container.RegisterType <IUserProcessor, UserProcessor>(); //声明UnityContainer并注册IUserProcessor IUserProcessor processor = container.Resolve <IUserProcessor>(); processor.RegUser(user); //调用 container.AddNewExtension <Interception>().Configure <Interception>() .SetInterceptorFor <IUserProcessor>(new InterfaceInterceptor()); //IUserProcessor userprocessor = new UserProcessor(); IUserProcessor userprocessor = container.Resolve <IUserProcessor>(); Console.WriteLine("********************"); userprocessor.RegUser(user); //调用 userprocessor.GetUser(user); //调用 } }
public async Task <string> logup(string username, string password) { var USER_AUTHORIZED = false; User user = null; //fetch clientinfo Client client = new Client(username, password); //open connection IDbConnection db = con.GetConnection(); //retrieve userinfo user = await upcr.GetUser(client); if (user == null) { USER_AUTHORIZED = true; if (await upcr.Create(client) == -1) { return("user created"); } } else { USER_AUTHORIZED = false; } if (USER_AUTHORIZED == true) { Console.WriteLine("token sent to user"); return(await token.createToken(user)); } else { Console.WriteLine("SORRY!!!token cant be sent"); return("wrong token"); } }
public static void Show() { User user = new User() { Name = "Ivan", Password = "******" }; { IUnityContainer container = new UnityContainer(); container.RegisterType <IUserProcessor>(); IUserProcessor processor = container.Resolve <IUserProcessor>(); processor.RegUser(user); } { IUnityContainer container = new UnityContainer(); ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "Unity.config"); Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); UnityConfigurationSection configurationSection = (UnityConfigurationSection)configuration.GetSection(UnityConfigurationSection.SectionName); configurationSection.Configure(container, "UnityAOPContainer"); IUserProcessor processor = container.Resolve <IUserProcessor>(); processor.RegUser(user); processor.GetUser(user); } }
public static void Show() { //Microsoft.Practices.Unity.Configuration. User user = new User() { Name = "Richard", Password = "******" }; IUnityContainer container = new UnityContainer(); //声明一个容器 container.RegisterType <IUserProcessor, UserProcessor>(); //声明UnityContainer并注册IUserProcessor //IUserProcessor processor = container.Resolve<IUserProcessor>(); //processor.RegUser(user);//调用 container.AddNewExtension <Interception>(); container.RegisterType <IUserProcessor, UserProcessor>() .Configure <Interception>() .SetInterceptorFor <IUserProcessor>(new InterfaceInterceptor()); //IUserProcessor userprocessor = new UserProcessor(); IUserProcessor userprocessor = container.Resolve <IUserProcessor>(); Console.WriteLine("********************"); userprocessor.RegUser(user); //调用 userprocessor.GetUser(user); //调用 }
public async Task <bool> Process() { await _accountProcessor.GetRecords <int>(); await _userProcessor.GetUser(); return(true); }
public static void Show() { User user = new User() { Name = "Anonymous1", Password = "******" }; { IUnityContainer container = new UnityContainer(); container.RegisterType <IUserProcessor, UserProcessor>(); IUserProcessor processor = container.Resolve <IUserProcessor>(); processor.RegUser(user); Console.WriteLine("============="); } { //Config unitycontainer IUnityContainer container = new UnityContainer(); ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "CfgFiles\\Unity.Config"); Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); UnityConfigurationSection configSection = (UnityConfigurationSection)configuration.GetSection(UnityConfigurationSection.SectionName); configSection.Configure(container, "aopContainer"); //aopContainer is the name of container in configruation file. IUserProcessor processor = container.Resolve <IUserProcessor>(); processor.RegUser(user); //processor.GetUser(user); Console.WriteLine("=============="); { // Test for caching behaviors User userNew1 = processor.GetUser(user); Console.WriteLine("=============="); //This time will directly come to exception loggin, for relevant object has been chached. User userNew2 = processor.GetUser(user); Console.WriteLine("=============="); } } }
public async Task <int> login(string username, string password) { User user = new User(); //fetch clientinfo Client client = new Client(username, password); //open connection IDbConnection db = await con.GetConnection(); //retrieve userinfo user = await upcr.GetUser(client, db); //match user USER_FOUND = await updr.CheckUserName(client, user); //match password if (USER_FOUND == true) { PASSWORD_MATCHED = await updr.CheckPassword(client, user); if (PASSWORD_MATCHED == true) { USER_AUTHORIZED = true; } } else { Console.WriteLine("try again"); } if (USER_AUTHORIZED == true) { Console.WriteLine("token sent to user"); return(await token.createToken(user)); } else { Console.WriteLine("SORRY!!!token cant be sent"); return(-1); } }
static void Main(string[] args) { User user = new User() { Name = "张三", Age = 19 }; IUnityContainer unityContainer = UnityContainerFactory.CreateContainer(); IUserProcessor iUserProcessor = unityContainer.Resolve <IUserProcessor>(); iUserProcessor.RegUser(user); iUserProcessor.GetUser(user); System.Console.ReadKey(); }