小编ebb*_*ebb的帖子

Ninject + Bind通用存储库

我正在尝试将一个通用的IRepository <>接口绑定到我的通用存储库<> - 但它总是返回null?

我尝试过各种各样的事情:

Bind(typeof(IRepository<CustomerModel>)).To(typeof(Repository<CustomerModel>)); 
Bind(typeof(IRepository<>)).To(typeof(Repository<>)); 
Run Code Online (Sandbox Code Playgroud)

但是,如果我传入非通用接口和类,那么它就像梦一样?

c# ninject ioc-container

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

ASP.NET MVC - 角色提供者的替代方案?

我试图避免使用角色提供者和成员资格提供者,因为在我看来它过于笨拙,因此我正在尝试制作我自己的"版本",它不那么笨拙,更易于管理/灵活.现在是我的问题..角色提供者有替代方案吗?(我知道我可以做自定义角色提供者,会员提供者等)

通过更易于管理/灵活,我的意思是我只能使用Roles静态类而不是直接实现到与数据库上下文交互的服务层,而是我必须使用具有自己的数据库上下文的Roles静态类等,表名也很糟糕..

提前致谢.

asp.net authentication asp.net-mvc authorization asp.net-membership

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

实体框架中的重复关键异常?

我正在尝试捕获当我将具有给定用户名的已存在用户插入我的数据库时抛出的异常.正如标题所说,我正在使用EF.当我尝试将用户插入到db时抛出的唯一异常是"UpdateException" - 如何提取此异常以识别它是重复的异常还是别的?

c# entity-framework exception

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

ASP.NET MVC - HttpException还是返回视图?

我正在尝试向客户提出请求,如果客户不存在,则应返回某种"未找到"页面.以下哪项是用于此类任务的最佳实践,为什么?

public ActionResult Index(int id)
{
    if (customerService.GetCustomerById(id) == null)
        return View("NotFound");

    return View();
}
Run Code Online (Sandbox Code Playgroud)

要么

public ActionResult Index(int id)
{
    if (customerService.GetCustomerById(id) == null)
        throw new HttpException(404, "Customer not found");

    return View();
}
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc

19
推荐指数
1
解决办法
3779
查看次数

类型提供者:如何重新生成?

您将如何创建LINQ-TO-SQL类型提供程序,生成或/和重新生成类?

我刚刚在我的数据库中添加了一个新表,而类型提供程序无法解决这个问题.我试图删除类型提供程序的行,并再次键入它 - 没有运气.我也试过重建......仍然没有运气.

编辑:

我已经定义了类型提供程序,如:

[<Generate>]
type dbSchema = SqlDataConnection<"conString">
Run Code Online (Sandbox Code Playgroud)

并使用它像:

let ctx = dbSchema.GetDataContext()

f# type-providers

19
推荐指数
1
解决办法
1214
查看次数

ASP.NET MVC - 在哪里抛出异常?

如果在数据库中找不到条目,​​则抛出异常的最佳做法是什么?

// CONTROLLER
public ActionResult Edit(int categoryId, int id)
{
    Product target = Products.GetById(id);
    if (target == null) throw new HttpException(404, "Product not found");

    return View("Edit", target);
}

// REPOSITORY
public Product GetById(int id)
{
    return context.Products.FirstOrDefault(x => x.productId == id);
}
Run Code Online (Sandbox Code Playgroud)

要么

// CONTROLLER
public ActionResult Edit(int categoryId, int id)
{
    return View("Edit", Products.GetById(id));
}

// REPOSITORY
public Product GetById(int id)
{
    Product target = context.Products.FirstOrDefault(x => x.productId == id);
    if (target == null) throw new HttpException(404, "Product not …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc exception

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

多个任务变慢

代码:

static void DoIt(string name)
{
    Console.WriteLine("Hello {0} | {1}", name, Thread.CurrentThread.ManagedThreadID);
    Thread.Sleep(5000);
    Console.WriteLine("Bye {0} | {1}", name, Thread.CurrentThread.ManagedThreadID);
}

static void Main()
{
    Task.Factory.StartNew(() => DoIt("One"));
    Task.Factory.StartNew(() => DoIt("Two"));
    Task.Factory.StartNew(() => DoIt("Three"));
    Task.Factory.StartNew(() => DoIt("Four"));
    Task.Factory.StartNew(() => DoIt("Five"));
    Task.Factory.StartNew(() => DoIt("Six"));
    Task.Factory.StartNew(() => DoIt("Seven"));
    Task.Factory.StartNew(() => DoIt("Eight"));
    Task.Factory.StartNew(() => DoIt("Nine"));
    Task.Factory.StartNew(() => DoIt("Ten"));

    Console.ReadKey();
}
Run Code Online (Sandbox Code Playgroud)

为什么它可以立即精确启动前3个任务,但是任务4启动需要5-10秒,在任务4启动后,任务5启动前需要5-10秒,依此类推.GC是做什么的吗?有人可以澄清一下发生了什么吗?

c# multithreading

17
推荐指数
2
解决办法
5049
查看次数

MVC3 + Ninject - 怎么样?

我刚开始玩IoC容器,因此选择了Ninject.

经过几个小时的汗水和眼泪,我仍然无法弄清楚如何使用Ninject设置我的MVC3应用程序.

到目前为止,我有:

的Global.asax.cs

public class MvcApplication : Ninject.Web.Mvc.NinjectHttpApplication
{
    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new HandleErrorAttribute());
    }

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

    }

    protected void Application_Start() 
    {
        DependencyResolver.SetResolver(new MyDependencyResolver(CreateKernel()));
        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);
    }

    protected override IKernel CreateKernel()
    {
        var modules = new [] { new ServiceModule() };
        return new StandardKernel(modules);
    } …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc ninject inversion-of-control

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

EF Code First - 如果模型更改,则重新创建数据库

我目前正在开发一个使用EF Code First和POCO的项目.到目前为止,我有5个POCO取决于POCO"用户".

在POCO"用户"应该是指我的现有成员关系表"aspnet_Users"(我在的DbContext的OnModelCreating方法其映射到).

问题是,我想借此优势"重新创建数据库如果模型变更"功能为斯科特谷表示在:http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development -with-entity-framework-4.aspx - 该功能基本上是在看到我的POCO中的任何更改后立即重新创建数据库.我想要它做的是重新创建数据库,但以某种方式不删除整个数据库,以便aspnet_Users仍然存在.然而,这似乎是不可能的,因为它要么创建一个全新的数据库,要么替换当前的数据库.

所以我的问题是:我注定要手动定义我的数据库表,还是我能以某种方式将我的POCO合并到我当前的数据库中,并且仍然可以使用该功能而无需全部擦除它?

entity-framework asp.net-membership poco

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

从c#中的不同线程启动一个计时器

嗨我已经陷入了一些与计时器相关的问题.希望有人可以帮忙..

  1. 我有一个包含按钮的窗体
  2. 当我点击该按钮时,我启动参数化线程
Thread thread1 = new Thread(new ParameterizedThreadStart( execute2));
thread1.Start(externalFileParams);
Run Code Online (Sandbox Code Playgroud)
  1. 线程内的代码执行得很好
  2. 在这个线程的最后一行,我启动一个计时器

.

public void execute2(Object ob)
{
    if (ob is ExternalFileParams)
    {
        if (boolean_variable== true)
          executeMyMethod();//this also executes very well if condition is true
        else
        {
            timer1.enabled = true;
            timer1.start();
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

5但是没有触发计时器的tick事件

我正在研究VS2008 3.5框架.我已经从工具箱拖动计时器并将其设置Interval为300也试图设置Enabledtrue/false方法timer1_Tick(Object sender , EventArgs e)但是它没有被解雇

任何人都可以建议我做错了什么?

c# multithreading timer visual-studio-2008

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