我有一种方法可以向我们的客户发送一些短信,如下所示:
public void ProccessSmsQueue()
{
SmsDbContext context = new SmsDbContext();
ISmsProvider provider = new ZenviaProvider();
SmsManager manager = new SmsManager(context, provider);
try
{
manager.ProcessQueue();
}
catch (Exception ex)
{
EventLog.WriteEntry(ex.Message, EventLogEntryType.Error);
}
finally
{
context.Dispose();
}
}
protected override void OnStart(string[] args)
{
Task.Factory.StartNew(DoWork).ContinueWith( ??? )
}
Run Code Online (Sandbox Code Playgroud)
我不知道方法运行需要多长时间;
该方法可以抛出异常,我想在EventLog上编写
我希望每10分钟在循环中运行此方法,但仅在最后一次执行完成后.
我怎么能做到这一点?我考虑过使用ContinueWith(),但我仍然对如何构建整个逻辑有疑问.
c# multithreading windows-services task-parallel-library async-await
恕我直言,最出色的DDD概念之一是应用程序中单独的上下文的能力.但我对如何将所有东西放在一起工作感到困惑.
首先,我知道有一件事与其他事无关.但我的问题完全在于Infrastructure/ORM部分.
例如,我有一个名为Procedure(医疗程序)的域对象.在注册的上下文中,唯一重要的是代码和名称.但是在程序管理上下文中,我有很多其他领域,比如Price,属于这个特定的上下文.
如何使用EF Code First在具有不同属性的两个具有相同名称(在不同上下文中)的实体?基本上,我想在同一个表中保存所有字段,但在一个上下文中只检索2个字段,在另一个上下文中检索所有字段.我怎么能做到这一点?
.net domain-driven-design entity-framework ef-code-first bounded-contexts
我在我的应用程序中为我的DbContexts提供了一个通用的UnitOfWork实现,其工作原理如下:
public class UnitOfWork<TContext> : IDisposable, IUnitOfWork<TContext>
where TContext : DbContext
{
private readonly TContext _context;
[..UoW default implementations..]
public void Dispose()
{
_context.Dispose();
}
}
Run Code Online (Sandbox Code Playgroud)
注册......:
public static class SimpleInjectorWebApiInitializer
{
/// <summary>Initialize the container and register it as Web API Dependency Resolver.</summary>
public static void Initialize()
{
var container = new Container();
container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();
InitializeContainer(container);
container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
container.Verify();
GlobalConfiguration.Configuration.DependencyResolver =
new SimpleInjectorWebApiDependencyResolver(container);
}
private static void InitializeContainer(Container container)
{
// For instance:
container.Register(typeof(IUnitOfWork<>), typeof(UnitOfWork<>), Lifestyle.Scoped);
container.RegisterWebApiRequest<IBankRepository, BankRepository>(); …Run Code Online (Sandbox Code Playgroud) c# ioc-container inversion-of-control simple-injector asp.net-web-api