dto

How to map datatable columns to properties of DTO object of Type T

风格不统一 提交于 2020-01-02 20:30:17
问题 How can map datatable columns with the properties of DTO object of Type T using LINQ query or Lambda expression. This should automatically map with any DTO. If there is a way to do this without hardcoding of column names of datatable DataTable dt = db.GetEmployees(); foreach(DataRow dr in dt.Rows) { var obj = new T(); PropertyInfo[] prop = obj.GetType().GetProperties(); var results = dt.AsEnumerable().Select(dr => new T { ///How to directly map type T properties in prop with columns in

ASP.NET Core 实战:基于 Jwt Token 的权限控制全揭露

南笙酒味 提交于 2020-01-02 03:07:18
一、前言   在涉及到后端项目的开发中,如何实现对于用户权限的管控是需要我们首先考虑的,在实际开发过程中,我们可能会运用一些已经成熟的解决方案帮助我们实现这一功能,而在 Grapefruit.VuCore 这个项目中,我将使用 Jwt 的方式实现对于用户的权限管控,在本章中,我将演示如何使用 Jwt 实现对于用户的授权、鉴权。   系列目录地址: ASP.NET Core 项目实战   仓储地址: https://github.com/Lanesra712/Grapefruit.VuCore 二、Step by Step   1、一些概念   Jwt(json web token),是一种基于 Json 的无状态授权令牌,因为 Jwt 是一种标准的数据传输规范,并不是某家所独有的技术规范,因此非常适用于构建单点登录服务,为 web、client、app 等等各种接口使用方提供授权服务。   在使用 Jwt 进行权限控制的过程中,我们需要先请求授权服务器获取到 token 令牌,将令牌存储到客户端本地(在 web 项目中,我们可以将 token 存储到 localstorage 或是 cookie 中),之后,对于服务端的每一次请求,都需要将获取到的 token 信息添加到 http 请求的 header 中。 $.ajax({ url: url, method: "POST",

Java DTO Object search mechanism?

♀尐吖头ヾ 提交于 2020-01-01 18:25:14
问题 I have produced a DTO object from 2 microservices. Profile and ProfileCredit. I am able to successfully retrieve a populated DTO object with relevant data. However I am further curious is it possible to query or do conditional filter on the generated DTO object? and if so what is the approach to achieve just that? For example using 'swagger' this is what gets returned Is it possible to filter by profileCredit field which is present in the dto but the data is retrieved within separate

How to handle Dtos for objects which implement multiple interfaces?

こ雲淡風輕ζ 提交于 2020-01-01 09:14:49
问题 We are using Dtos in our WCF service interface, but have started to come across issues when the Business Object that the Dto represents implements more than a single interface and we want to return the Dtos in those different contexts and to also be able to treat the Dtos polymorphically on the client. For example lets say we have an interface for an IBusinessObject with several properties containing details of the relationships of the object, attributes of the object etc etc. I have several

Spring DTO validation in Service or Controller?

房东的猫 提交于 2019-12-31 21:35:53
问题 I'm building a straight forward AJAX / JSON web service with Spring. The common data flow is: some DTO from browser v Spring @Controller method v Spring @Service method I'm looking for the most easy way to handle data validation. I know the @Valid annotation which works pretty well inside @Controller methods. Why does @Valid not work within @Service methods? I mean: A service method can be used by any other service and controller. So wouldn't it make much more sense to validate at @Service

Spring DTO validation in Service or Controller?

只愿长相守 提交于 2019-12-31 21:35:07
问题 I'm building a straight forward AJAX / JSON web service with Spring. The common data flow is: some DTO from browser v Spring @Controller method v Spring @Service method I'm looking for the most easy way to handle data validation. I know the @Valid annotation which works pretty well inside @Controller methods. Why does @Valid not work within @Service methods? I mean: A service method can be used by any other service and controller. So wouldn't it make much more sense to validate at @Service

Should I use DTOs as my data models in MVVM?

风格不统一 提交于 2019-12-31 13:27:09
问题 I'm currently working on what will be my first real foray into using MVVM and have been reading various articles on how best to implement it. My current thoughts are to use my data models effectively as data transfer objects, make them serializable and have them exist on both the client and server sides. It seems like a logical step given that both object types are really just collections of property getters and setters and another layer in between seems like complete overkill. Obviously

Placement of DTO / POCO in a three tier project

人盡茶涼 提交于 2019-12-30 10:31:12
问题 I've been in the process of re-writing the back-end for a web site and have been moving it towards a three-tiered architecture. My intention is to structure it so: Web site <--> WCF Service (1) <--> Business Layer (2) <--> Data Layer (3) My issue is with the placement of the DTO's within this structure. I'll need to use DTO's to move data between the business layer and the WCF service and from the WCF service to the consuming web site. During my research on here I've read some excellent

Model-View-Presenter模式之 Step by Step

拜拜、爱过 提交于 2019-12-29 09:48:14
长 期以来,一直在C/S的世界里埋头苦干,偶尔会有朋友问我为什么没转向Web。我想,暂时的,除了架构与模式,我还没有额外的时间和精力。但归根结底,无论C/S亦或B/S,Server才是最让我着迷的部分。其中,UI无关的设计一直是分层架构方案的重要组成。它和无关持久化PI(Persistence Ignorance)一样,可以让我们把UI呈现相对独立出来,与应用层和领域模型脱耦。简单地说,就是可以把一个基于WinForm实现的UI换成ASP.NET等Web形式的,或者同时支持窗口与报表两种UI形式,而不影响其他层的实现。 具体到实践中,MVC模式( Model-View-Controller )已经成为了UI无关设计的经典,在企业架构中得到广泛应用。Model维护业务模型与数据,View提供呈现,Controller控制程序流程、传递和处理请求。本质上,这是一种Observer模式的具体实现。但是,MVC如此普及,却并非完美。它也有缺点,其中包括View可以直接访问Model,View中耦合了一部分业务对象转换的逻辑。即便是常见的ASP.NET的MVC,也不是一种纯粹的MVC,因为在ASP.NET的结构里,并没有一个严格的、独立的领域模型。 于是,MVP( Model-View-Presenter )逐渐步入了我们的视野。在领域驱动设计的方式下,作为系统核心的领域模型层

C# model转Dto 使用泛型即可实现

流过昼夜 提交于 2019-12-26 04:42:28
C# model转Dto 使用泛型即可实现 using System ; using System . Collections . Generic ; using System . Linq ; using System . Reflection ; using System . Text ; using System . Threading . Tasks ; namespace GlobalAPI { public class PropertyHelper { /// <summary> /// 反射得到实体类的字段名称和值 /// var dict = GetProperties(model); /// </summary> /// <typeparam name="T">实体类</typeparam> /// <param name="t">实例化</param> /// <returns></returns> public static Dictionary < object , object > GetProperties < T > ( T t ) { var ret = new Dictionary < object , object > ( ) ; if ( t == null ) { return null ; } PropertyInfo [ ]