鉴于代码:
dynamic foo = new ExpandoObject();
foo.Bar = "something";
string json = Newtonsoft.Json.JsonConvert.SerializeObject(foo);
Run Code Online (Sandbox Code Playgroud)
输出如下:
"{\"Bar\":\"something\"}"
Run Code Online (Sandbox Code Playgroud)
在调试大型json文档时,很难阅读 - 使用Newtonsoft.Json的内置功能(不是正则表达式或可能破坏事物的黑客)有没有办法使输出成为一个带有valie的字符串:
{Bar: "something"}
Run Code Online (Sandbox Code Playgroud) 我使用的是Thinktecture AuthorizationServer(AS),它运行良好.
我想编写一个原生的javascript单页应用程序,可以直接调用WebAPI,但隐式流程不提供刷新令牌.
如果进行了AJAX调用,如果令牌已过期,API将向登录页面发送重定向,因为数据使用动态弹出窗口,这将中断用户.
Facebook或Stackoverflow如何做到这一点,仍然允许页面上运行的javascript调用API?
提出的解决方案
下面的场景是否合理(假设可以使用iframe):
我的SPA指示我到AS,我通过Implicit Flow获得一个令牌.在AS中,我单击允许Read data
范围,然后单击Remember decision
,然后单击Allow
按钮.
由于我点击了Remember decision
按钮,每当我点击AS作为令牌时,会自动传回一个新令牌,而我无需登录(我可以看到FedAuth cookie记住了我的决定并相信这使得它能够正常工作).
使用我的SPA(不受信任的应用程序),我没有刷新令牌只有一个访问令牌.所以相反我:
如果FedAuth cookie被盗,我想我仍然会遇到麻烦.
针对上述场景的任何标准或推荐方式?
我正在使用Entity Framework并有一个BusinessUnits表,它可以引用相同类型的另一个记录来形成子父层次结构.
我还有一组用户和用户权限,其中此表中定义的每个用户都应该可以访问BusinessUnit和层次结构中的所有子业务单位.用户不应该访问引用的BusinessUnit(如果存在).
如何构建LINQ查询来处理此自引用关系树并返回此用户可以访问的所有业务单位(具有子单元)?是否可以在一个查询中执行,或者我是否需要使用for循环手动构建树?
我已经看到了schema从节点到父节点的方式引用,这是否意味着我必须从最远的子节点开始一次由一个父节点构建树?
提前致谢,
克里斯
class BusinessUnit
{
int BusinessUnitID {get;set;}
public string BusinessName {get;set;}
BusinessUnit ParentBusinessUnit {get;set;}
}
class User
{
int UserID {get;set;}
string Firstname {get;set;}
}
class UserPermissions
{
[Key, ForeignKey("BusinessUnit"), Column(Order = 0)]
BusinessUnit BusinessUnit {get;set;}
[Key, ForeignKey("User"), Column(Order = 1)]
User User {get;set;}
}
IEnumerable<BusinessUnit> GetUnitsForWhichUserHasAccess(User user)
{
/* Example 1
given: BusinessUnitA (ID 1) -> BusinessUnitB (ID 2) -> BusinessUnitC (ID 3)
with user with ID 1:
and UserPermissions with an entry: …
Run Code Online (Sandbox Code Playgroud) 我有一个在td
元素上有一个单选按钮的表,但我无法设置宽度(我的页面在HTML5中,所以使用样式css属性来设置宽度).
我的行如下:
<h3><span data-bind="text: description"></span></h3>
<table class="table table-striped table-condensed">
<thead>
<tr>
<th colspan="2">Description</th>
<th>Setup</th>
<th>Monthly</th>
</tr>
</thead>
<tbody>
<!-- ko foreach: options -->
<tr>
<td style="width:16px"><input type="radio" data-bind=" attr: { name: $parent.name }, checkedValue: $data, checked: $parent.selection" /></td>
<td><span data-bind="text: description"></span></td>
<td><span data-bind="text: setup == 0 ? '-' : setup"></span></td>
<td><span data-bind="text: price == 0 ? '-' : price"></span></td>
</tr>
<!-- /ko -->
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
事实上,所有行都是154px宽,每行相等.
不要担心数据绑定属性,我正在使用knockoutjs.我使用bootstrap进行stlying,但是看不到任何列宽度应用于bootstrap CSS.
我在下面截取了chrome的截图:
编辑和进一步的信息
在看了@ daker评论这里的小提琴http://jsfiddle.net/g18c/Lnvny/之后,我可以看到宽度已经应用好了.
当我查看我的代码时,我有一个导致问题的thead部分,这在上面的小提琴中不存在.
将以下thead
部分添加到小提琴中会阻止宽度应用于 …
我有一个聚合根Products
,其中包含一个实体列表Selection
,这些实体又包含一个被调用的实体列表Features
.
Product
具有名称的标识Selection
具有名称标识(及其相应的产品标识)Feature
具有名称标识(以及它的相应选择标识)实体的身份构建如下:
var productId = new ProductId("dedisvr");
var selectionId = new SelectionId("os",productId);
var featureId = new FeatureId("windowsstd",selectionId);
Run Code Online (Sandbox Code Playgroud)
请注意,从属标识将父标识作为组合的一部分.
这个想法是,这将形成产品部件号,可以通过选择中的特定特征来识别,即ToString()
上述featureId对象将返回dedisvr-os-windowsstd
.
所有内容都存在于Product聚合中,其中使用业务逻辑来强制选择和功能之间的关系不变.在我的域中,没有选择而没有相关产品的选择存在功能是没有意义的.
在查询产品以查找关联功能时,将返回Feature对象,但C#internal
关键字用于隐藏任何可能使实体变异的方法,从而确保实体对调用应用程序服务不可变(在与域代码不同的程序集中) .
上述两个断言由两个函数提供:
class Product
{
/* snip a load of other code */
public void AddFeature(FeatureIdentity identity, string description, string specification, Prices prices)
{
// snip...
}
public IEnumerable<Feature> GetFeaturesMemberOf(SelectionIdentity identity);
{
// snip...
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个称为服务订单,这将包含一个ConfigurationLine其将引用聚合根Feature …
我有一个可由用户配置的数据库应用程序 - 其中一些选项是从不同的外部插件系统中选择的.
我有一个基本插件类型,我的数据库架构具有相同的插件记录类型具有相同的字段.我有一个PlugingMananger
在应用程序启动时加载插件(通过IoC容器)并将它们链接到数据库(基本上将磁盘插件中的字段复制到数据库).
public interface IPlugin
{
Guid Id{ get; }
Version Version { get; }
string Name { get; }
string Description { get; }
}
Run Code Online (Sandbox Code Playgroud)
然后可以使用检索插件PlugingMananger.GetPlugin(Guid pluginId, Guid userId)
,其中用户ID是可以调用插件动作的多个用户之一的用户ID.
应用程序已经预先声明了一组已知的接口,每个接口都特定于某个函数(格式化程序,外部数据,数据发送器等),如果插件实现了一个未知的服务接口,那么它将被忽略:
public interface IAccountsPlugin : IPlugin
{
IEnumerable<SyncDto> GetData();
bool Init();
bool Shutdown();
}
Run Code Online (Sandbox Code Playgroud)
插件还可以PluginSettingAttribute
在多用户系统中为每个用户定义设置属性- 这些属性是在为特定用户检索插件时设置的,以及PluginPropertyAttribute
用于所有用户通用的属性和插件一次设置的只读属性当插件在应用程序启动时注册.
public class ExternalDataConnector : IAccountsPlugin
{
public IEnumerable<AccountSyncDto> GetData() { return null; }
public void Init() { }
public void Shutdown() { }
private …
Run Code Online (Sandbox Code Playgroud) 我正在使用实体框架Model-First Repository
和Unit of Work
模式,存储库返回EF POCO.
我假设我无法向由Entity Framework生成的POCO添加行为,因此我的代码现在已经充满了类似于XyzService
实现生成的Entity Framework的业务逻辑的单独类Xyz POCO
.
我有以下问题:
这有一个糟糕的代码味道,因为我不仅有EF POCO,我为每个POCO提供服务.除了许多类之外,业务逻辑还在业务实体之外分割.这是贫血反模式的一个例子吗?
如果我坚持EF,有什么方法可以添加行为(即通过部分类)或其他方式?
看到使用来自数据层的返回业务实体的持久无知模式(在我们的例子中是一个存储库),如果我想从中EF-MODEL -> REPOSITORY-DAL -> BIZ-ENTITY
看到,那么在业务实体和EF模型POCO之间会有很多双向映射.Automapper等实用程序可以优雅地处理我可能面临的嵌套对象的复杂关系吗?
为了减少与对应的EF模型实体重复的业务实体,我是不是更好地删除EF并且只为每个存储库使用LINQ to SQL编写我自己的存储库实现?
任何推荐的方式,让我专注于代码(而不是像我一样首先固定在EF模型上),然后当我准备编写持久层时,仍然使用实体框架,但避免了很多这样做的额外工作和映射?EF Code-First在这方面会更好吗?
如果我错过了其他任何可以帮助开发的技术(例如NHibernate),那么请随意提及.
我在Windows Service Bus 1.0的前提下运行,我得到了例外MessaingEntityNotFoundException 40400: Endpoint not found
.
这是因为没有创建队列吗?我无法在服务器上的任何地方看到我可以创建队列(我正在使用2K8R2),当我运行服务总线配置工具时,它只询问我是否要从服务器场中删除.
我是否需要添加一个队列,如果有的话是gui或powershell脚本,还是我做了别的错误?
app.config中的连接字符串
<appSettings>
<!-- Service Bus specific app setings for messaging connections -->
<add key="Microsoft.ServiceBus.ConnectionString" value="Endpoint=sb://sqldev1.domain.local/domaintest1;StsEndpoint=https://sqldev1.domain.local:9355/domain-test1;RuntimePort=9354;ManagementPort=9355" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.ServiceBus;
using Microsoft.ServiceBus.Messaging;
using System.Threading.Tasks;
namespace WindowsServerEventBus
{
class Program
{
static void Main(string[] args)
{
MessagingFactory messageFactory = MessagingFactory.Create();
NamespaceManager namespaceManager = NamespaceManager.Create();
QueueClient myQueueClient = messageFactory.CreateQueueClient("WowWowWee");
BrokeredMessage sendMessage = new BrokeredMessage("Hello World!");
myQueueClient.Send(sendMessage);
BrokeredMessage receivedMessage = myQueueClient.Receive(TimeSpan.FromSeconds(5));
if (receivedMessage …
Run Code Online (Sandbox Code Playgroud) I am trying to use Bootstrap 3 vertical scrollspy, however I cannot find any examples included in the source.
I went ahead and stripped out the documentation pages from here http://getbootstrap.com/javascript/ but I am getting some very strange resize bugs with the sidebar - specifically:
On page refresh the nav bar is positioned and works OK, but on page resize it can drop off past the footer, or disapear before the end of the content.
When refreshed and the browser …
扩展这个现有问题微服务:工作者角色、API 或两者兼而有之?:
我见过将微服务实现为工作者角色处理队列外请求和/或 API (REST) 的混合示例。
支持异步场景,可以使用队列,通过一个简单的哑队列监听器将请求转发到微服务 REST API,而同步场景将直接调用 REST API。
我认为微服务这个术语的定义很模糊;人们是否将它们视为 API(例如 RESTful 服务)或任何抽象服务处理请求,但提供了该请求?
我们将使用什么命名约定来区分作为 API 运行的服务,或作为后台工作线程运行的服务(从消息队列中提取或每隔一段时间运行任务)?
区分这一点很重要,以便明确意图,因为 Web 应用程序的托管技术允许多个工作线程并行扩展,而我们可能希望在任何时间运行单个工作线程来执行预定的维护任务。
更多信息如下。
预定的后台工作者或 ServiceProxy
在某些情况下,我们可能会代理调度的后台工作人员来调用服务,即:
我们怎么称呼这样的ServiceProxy
后台工作人员?我想如果我们担心并发问题和多个这些后台工作人员并行运行,那么这可以在调用服务本身时解决。
客户端库
我建议使用一个客户端库来包含:
对于上面的第 2 点和第 3 点,除了有关如何发送数据的详细信息的函数名称之外,没有其他指示,即RegisterEndPoint(Guid id, string name)
在内部使用标准的 WebAPI 调用和SendUpdate(Guid id, HealthPoco stats)
使用消息总线……客户端将使用该库而不用担心细节。
项目结构
到目前为止,我有一个项目结构:
ExampleSolution.Assets.Service
- 对于 WebAPI 或 gRPC 服务,其中多个可以并行运行ExampleSolution.Assets.ServiceProxy
- 这是一个后台工作者,通常我们想要一个运行ExampleSolution.Assets.Client
- 这是允许与服务通信的客户端库ExampleSolution.Assets.Common
- 相关的公共信息,如数据合同ExampleSolution.EndPoint.CoreAgentApp
- 在 Windows 或 …projects-and-solutions directory-structure naming-conventions project-structure microservices