小编Man*_*kas的帖子

将Autofac与域事件一起使用

我正在尝试将域事件引入项目中.这个概念在Udi Dahan的帖子中描述 - http://www.udidahan.com/2009/06/14/domain-events-salvation/

这是域事件代码

public interface IDomainEvent { }

public interface IHandleDomainEvents<T> where T : IDomainEvent
{
     void Handle(T args); 
}

public interface IEventDispatcher
{
    void Dispatch<TEvent>(TEvent eventToDispatch) where TEvent : IDomainEvent;
}

public static class DomainEvents
{
    public static IEventDispatcher Dispatcher { get; set; }

    public static void Raise<TEvent>(TEvent eventToRaise) where TEvent : IDomainEvent
    {
        Dispatcher.Dispatch(eventToRaise);
    }
}
Run Code Online (Sandbox Code Playgroud)

最重要的部分是IEventDispatcher实现,它将域事件与引发事件时发生的任何事件分离开来.诀窍是通过容器连接这个耦合.这是我的尝试

注册所有域事件处理程序的代码....

        var asm = Assembly.GetExecutingAssembly();
        var handlerType = typeof(IHandleDomainEvents<>);

        builder.RegisterAssemblyTypes(asm)
            .Where(t => handlerType.IsAssignableFrom(t)
                        && t.IsClass
                        && !t.IsAbstract)
            .AsClosedTypesOf(handlerType)
            .InstancePerLifetimeScope(); …
Run Code Online (Sandbox Code Playgroud)

autofac domain-events

14
推荐指数
1
解决办法
3324
查看次数

CQRS和域事件

CQRS让我进入思维模式.我正在尝试用CQRS创意开始一个新项目.我喜欢的主要内容是
1)Query和Command的分离.我们的域查询一直是个问题.
2)使用事件存储进行审计 - 我不会将其用于重播 - 至少现在不是.

我很擅长查询方面,我仍然对域事件有一些疑问

如果一个命令导致多个聚合根(例如订单和订单详细信息)的更新,我将把它们限定在UnitofWork(事务性)下.现在,每个域负责在更改发生到其状态时发布事件.

让我们说该命令更改3 orderDetail记录.每个OrderDetail将发布2个事件.最后我们有6个活动.

a)如果我在对域对象进行更改(但未提交事务)后立即发布事件,如何撤消已发布的事件(并且可能已被订阅者使用)

  • 我能想到的是将事件保存在"同一工作单元范围内"的列表中,并且一旦调用了事务提交,就将其存储并发布.这听起来像是人们会做的事吗.

b)如果OrderDetail中的更改要求在Order Aggregate Root中进行某些更改,那么
i)我应该通过处理OrderDetail Aggregate发布的事件来进行这些更改吗?对于前者 让我们说两个订单明细被删除.这使订单状态从"首选"变为"不首选".ii)如果事件错误并且没有更新订单状态怎么办 - 如果订单仍然是首选,那么它将在2天内发货.

添加另一个问题
c)"域事件是所有应用程序状态更改的来源"还是"所有应用程序状态更改的结果"

先感谢您,

三月

cqrs domain-events

13
推荐指数
1
解决办法
3173
查看次数

基于没有键定义 mvc5 的类

我尝试从这个控制器添加视图。我只需要这个视图来显示不用于插入、更新或删除的数据

public ActionResult Index()
{
    var CartObj = ShoppingCart.GetCart(this.HttpContext);

    var classshop = new New
    {
        CartItems = CartObj.GetCartItems(),
        CartTotal = CartObj.GetSum()
    };

    return View(classshop);
}

namespace MusicStore.Models
{
    public class ShoppingCart
    {
        MusicStoreEntities dbo = new MusicStoreEntities();
        string ShoppingCartID { get; set; }

        public const string CartSessionKey = "CartId";
        public static ShoppingCart GetCart(HttpContextBase Context)
        {
            var cart = new ShoppingCart();
            cart.ShoppingCartID = cart.GetCardId(Context);
            return cart;
        }
        public static ShoppingCart GetCart(Controller controller)
        {
            return GetCart(controller.HttpContext);
        }

        public  List<Cart> GetCartItems()
        {
            return …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc asp.net-mvc-5

5
推荐指数
1
解决办法
4262
查看次数

Thymeleaf值发送angularJS ng-onclick方法

我的问题是thymeleaf与angularJS的整合.我有这个thymleaf页面:

<div ng-controller="ctrlsubcomment" >
    <div class="media" th:fragment="comments"  th:each="newsComment : ${comments}">
        <img class="media-object" src="/resources/images/adam1.jpg" alt="" width="52" height="52" />
        <div class="media-body">
            <div class="media-heading"> 
                <span th:text="${newsComment.comment.user.name}"></span>
                <span th:text="${newsComment.comment.user.surname}"></span>
                <small>
                    <span class="glyphicon glyphicon-calendar"></span>
                    <span th:text="${newsComment.comment.creationTime}"></span>
                </small>
            </div>
            <span th:text="${newsComment.comment.text}"></span>
            <img th:if="${newsComment.comment.image != null and newsComment.comment.image.fileExist()}" th:src="${newsComment.comment.image.getImageData()}" alt="" width="160" height="120"/>
            </div>
            <div class="media-icons" >
                <div class="btn-group" role="group" aria-label="...">
                    <span th:inline="text" th:text="${newsComment.comment.id}">${newsComment.comment.id}</span>
                        <a href="#"  class="btn btn-success btn-xs"><span class="glyphicon glyphicon-thumbs-up"></span> (45)</a>
                        <a href="#"  class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-thumbs-down"></span> (12)</a>
                        <button type="button" ng-click="addSubComment(${newsComment.comment.id})" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#cevapla"> …
Run Code Online (Sandbox Code Playgroud)

javascript ajax spring angularjs thymeleaf

5
推荐指数
1
解决办法
3523
查看次数

如何在单选按钮上调用Javascript函数而不是单击焦点

我有一个表格,每一行都包含一个单选按钮。我onclick在这样的单选按钮上调用JavaScript函数事件

<input type="radio" id="rdbSelect" name="Select" onclick="MyFunction()" />
Run Code Online (Sandbox Code Playgroud)

但是当我按Down/Up键盘上的箭头时,焦点Next/Previous再次转到单选按钮功能调用。

我希望仅在用鼠标单击单选按钮时(而不是在焦点上)调用该函数。

这是我的代码

的HTML

<div style="width:400px">
    <table class="style1" id="Table1">
        <tr>
            <td>
                <input type="text" id="text1" />
            </td>
            <td>
                <input type="text" id="text2" />
            </td>
            <td>
                <input type="radio" id="rdbSelect" name="Select" onclick="Test()" />
            </td>
        </tr>
    </table>
</div>
Run Code Online (Sandbox Code Playgroud)

和JavaScript

function CreateGrid() {
    var Grid = document.getElementById('Table1')
    for (var i = 1; i < 6; i++) {
        var newrow = Grid.rows[Grid.rows.length - 1].cloneNode(true);
        newrow.cells[0].innerText;
        newrow.cells[1].children[0].value = '';
        newrow.cells[2].children[0].value = '';
        Grid.getElementsByTagName('tbody')[0].appendChild(newrow);
    }
} …
Run Code Online (Sandbox Code Playgroud)

html javascript onclick

5
推荐指数
1
解决办法
4万
查看次数

javascript函数在jquery $(document).ready块中不起作用

我试图JavaScriptonclick触发器调用函数.

HTML 部分:

<div class="my_radio">
    <input type="radio" name="my_radio" value="1" onclick="my_func()"/>  first button
</div><!-- end of class my_radio -->
Run Code Online (Sandbox Code Playgroud)

JavaScript代码

<script type="text/javascript">
    $(document).ready(function(){
        function  my_func(){
            alert("this is an alert");
        }
    });
</script>
Run Code Online (Sandbox Code Playgroud)

这是行不通的.

但是,如果我将该JavaScript功能 保留在$(document).ready()代码之外,它就可以工作.以下是相关的代码段:

<script type="text/javascript">
    $(document).ready(function(){
        function  my_func111(){
            alert("this is an alert");
        }
    });

    function  my_func(){
        alert("this is an alert");
    }
</script>
Run Code Online (Sandbox Code Playgroud)

1)为什么第一个JavaScript代码片段不起作用?

2)如何让第一个JavaScript代码段工作?

编辑:

因此我知道,$(document).ready()当网页完全加载时执行.那么my_func()如果我my_func()在外面写,如何防止在完整页面加载之前或之后激活$(document).ready()

javascript jquery

4
推荐指数
2
解决办法
2万
查看次数

检查DataGridView上的所有复选框项

这是场景.

我有checkbox(名称:"全部检查"ID:chkItems)和datagridview.当我点击这个复选框时,datagridview也会检查遗嘱上的所有复选框.

我还在网格上添加了复选框列.

DataGridViewCheckBoxColumn CheckboxColumn = new DataGridViewCheckBoxColumn();
CheckBox chk = new CheckBox();
CheckboxColumn.Width = 20;
GridView1.Columns.Add(CheckboxColumn);
Run Code Online (Sandbox Code Playgroud)

这是复选框背后的代码.有一个问题row.Cell

private void chkItems_CheckedChanged(object sender, EventArgs e)
{
    foreach (DataGridViewRow row in GridView1.Rows)
    {
        DataGridViewCheckBoxCell chk = e.row.Cells(0);
        if (chk.Selected == false)
        {
            row.Cells(0).Value = true;
        }
    }
}   
Run Code Online (Sandbox Code Playgroud)

已解决(这是解决方案)

private void chkItems_CheckedChanged(object sender, EventArgs e)
{   
    foreach (DataGridViewRow row in GridView1.Rows)
    {
        DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)row.Cells[1];
        if (chk.Selected == false)
        {
            chk.Selected = true; …
Run Code Online (Sandbox Code Playgroud)

c# checkbox datagridview winforms

4
推荐指数
1
解决办法
5万
查看次数

如何在 openweather API 中获取地理位置

如何让 mu openweather API 与地理定位一起使用?这是我当前的 html 代码:

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="http://s3.amazonaws.com/codecademy-content/courses/ltp/css/bootstrap.css">
        <link rel="stylesheet" href="main.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <script type='text/javascript' src='app.js'></script>
    </head>
    <body>
        <div class="jumbotron">
            <button onclick="getLocation()">Get my location.</button>
            <p id="demo"></p>

            <script>
                var x = document.getElementById("demo");
                function getLocation() {
                    if (navigator.geolocation) {
                        navigator.geolocation.getCurrentPosition(showPosition);
                    } else { 
                        x.innerHTML = "Geolocation is not supported by this browser.";
                    }
                }

                function showPosition(position) {
                    x.innerHTML = "Latitude: " + position.coords.latitude + 
                                  "<br>Longitude: " + position.coords.longitude;    
                }
            </script>

            <p>The weather outside is: </p> 
            <div …
Run Code Online (Sandbox Code Playgroud)

javascript geolocation openweathermap

4
推荐指数
1
解决办法
1万
查看次数

可视化:未捕获的类型错误:无法读取未定义的属性“arrayToDataTable”

我正在尝试从我创建但失败的数据数组中绘制图形。我尝试了我在这里看到的关于相同主题的所有内容,但没有帮助。请指教。同一页面中有 HTML,但我认为显示并不重要。

<script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src = "http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"> </script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">

function getData(dateRange){
    var date = new Date();
    var currentDateInFormat = date.getFullYear() + "-" + date.getDate() + "-" + date.getMonth() + 1;
    var BASE_URL = 'https://query.yahooapis.com/v1/public/yql?q=';
    var yql_query_for_table_data;

    var dataArray = ['Date' , 'Stock Value'];

    if(dateRange === "year"){
        yql_query_for_table_data = 'select * from yahoo.finance.historicaldata where symbol = "YHOO" and startDate = "2009-09-11" and endDate = "2010-03-01"';
    }
    else if(dateRange === "halfYear"){
        yql_query_for_table_data …
Run Code Online (Sandbox Code Playgroud)

javascript datatables google-visualization

3
推荐指数
1
解决办法
5766
查看次数

无法从 Resources.resx 获取新添加的文件

我正在尝试将新文件添加到Resources.resx,但是Resources.Designer.cs没有使用新文件进行更新,并且我无法通过 获取该文件Assembly。它只显示一个文件,该文件是前一段时间添加的。

我尝试设置到Access Modifier并希望解决该问题,但随后我在 中遇到错误。Resources.resxInternalPublicResources.Designer.cs Ambiguity between 'Resources.resourceCulture' and 'Resources.resourceCulture

有些帖子建议单击Run Custom tool,但当我单击文件右键时没有这样的选项Resources.resx

有谁知道我缺少什么来进行Resources.Designer.cs更新?

c# resx visual-studio visual-studio-2015

3
推荐指数
1
解决办法
1833
查看次数