我在容器中注册了一堆TaskParametes类实例,如:
builder.Register(c => [some type instantiation]
)).Named<TaskParameters>("someTask").InstancePerDependency();
builder.Register(c => [some type instantiation]
)).Named<TaskParameters>("someOtherTask").InstancePerDependency();
Run Code Online (Sandbox Code Playgroud)
这些类可以在应用程序的任何模块中注册.我想获取可用的命名实例列表以将其发送到客户端,客户端应该按名称实例化并执行它.
是否有选项可以获取名称列表,而无需实际实例化类型?目前我正在挖掘IComponentContext的ComponentRegistry,我得到了,var ctx = Container.Resolve<IComponentContext>();我是否朝着正确的方向前进?
我在MassTransit中完成了一个简单的发布者.我正在间隔发送消息,并且能够使用MassTransit从.NET客户端接收消息.但是当我尝试从Python中观察某些东西时,它是沉默的.有没有办法从Python或其他语言中使用MassTransit?举例赞赏.
出版商:
builder.Register(c => ServiceBusFactory.New(sbc => {
sbc.UseRabbitMq();
sbc.UseBsonSerializer();
sbc.UseLog4Net();
sbc.ReceiveFrom("rabbitmq://localhost/masstransit");
});
Run Code Online (Sandbox Code Playgroud)
.NET客户端:
public void Execute(IJobExecutionContext context) {
using (var scope = ServiceLocator.Current.GetInstance<ILifetimeScope>().BeginLifetimeScope()) {
var log = scope.Resolve<ILog>();
log.Debug("Sending queue message");
var bus = scope.Resolve<IServiceBus>();
bus.Publish(new SimpleTextMessage{Text = "some text"});
}
}
Run Code Online (Sandbox Code Playgroud)
Python客户端:
import pika
print('Stating consumer')
connection = pika.BlockingConnection(pika.ConnectionParameters(
host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='python_consumer_1')
print ' [*] Waiting for messages. To exit press CTRL+C'
def callback(ch, method, properties, body):
print " [x] Received %r" % (body,)
channel.basic_consume(callback, queue='python_consumer_1')
channel.start_consuming() …Run Code Online (Sandbox Code Playgroud) 通常我有以下情况:有一个PONO类,其中包含属性列表.
public string UserName
{
get { return this.userName; }
set { if (this.userName != value) { SetDirty(); this.userName = value; } }
}
public string Password
{
get { return this.password; }
set { if (this.password != value) { SetDirty(); this.password = value; } }
}
public string Email
{
get { return this.email; }
set { if (this.email != value) { SetDirty(); this.email = value; } }
}
public string Title
{
get { return this.title; }
set …Run Code Online (Sandbox Code Playgroud) Quesiton相对于 罗斯林.RSP文件的引用
安装了Roslyn,玩:C:\ Users \name\Documents\Microsoft Codename Roslyn CTP - 2011年10月\ CSharp\WpfSeedRepl演练:http://msdn.microsoft.com/ru-ru/hh543924.
我无法加载当前的DLL和csx:
> #r "wpfseed.exe" (1,1): error CS0006: Metadata file 'wpfseed.exe' could not be found > #load "setup.csx" Specified file not found. Searched in directory: C:\Users\name >
在另一方面:
> Console.WriteLine(Environment.CurrentDirectory); C:\Users\name\Documents\Microsoft Codename Roslyn CTP - October 2011\CSharp\WpfSeedRepl
是否有任何解决方法不指定项目文件夹?
似乎Monitor在WinRT商店应用程序中无法正常工作.我有以下代码:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var tasks = Enumerable.Range(0, 10).Select((i)=>new Task(DoWork)).ToArray();
foreach (var task in tasks)
{
task.Start();
}
Task.WaitAll(tasks);
}
static object lockObject = new Object();//typeof(MainPage)
protected async void DoWork()
{
bool taken =false;
Monitor.Enter(lockObject, ref taken);
Debug.WriteLine("In");
await Task.Delay(1000);
Debug.WriteLine("Out");
if (taken) Monitor.Exit(lockObject);
}
Run Code Online (Sandbox Code Playgroud)
在输出窗口中,我看到:
In
In
In
In
In
In
In
Out
Out
Out
Out
Out
Out
Out
In
Out
A first chance exception of type 'System.Threading.SynchronizationLockException' occurred in App4.exe
Run Code Online (Sandbox Code Playgroud)
这意味着Monitor没有锁定关键区域.有没有人知道我做错了什么?
c# ×4
.net ×1
autofac ×1
extraction ×1
masstransit ×1
python ×1
rabbitmq ×1
regex ×1
roslyn ×1
textedit ×1
winrt-async ×1