我正在使用Microsoft Orleans,我有一个名为ConsumerGrain的粒子,它通过订阅ID与Azure订阅相关联。谷物注入了几种应用服务,以符合SOLID原则。某些应用程序服务需要订阅的ID。我不想在每个方法调用上传递订阅ID,而是希望将ISubscriptionContext对象注入到需要当前订阅ID的每个应用程序服务中,并且我希望每个应用程序创建一次服务实例grain的对象图,因此它不能是Transient而不是Singleton的生活方式。可以在这里使用Scoped生活方式吗?
答案 0 :(得分:0)
Orleans使用Silo private void Undo()
{
if (this.undo.Count == 0)
return;
// pop indexes of last line (start index is one below top of stack)
int to = this.undo.Pop();
int from = this.undo.Pop();
// remove last line from UIElement collection
this.paintCanvas.Children.RemoveRange(from, to);
}
类返回的IServiceProvider
仅用于谷物解析。这意味着应用程序可以在Startup
类中返回具有以下逻辑的复合IServiceProvider:
Startup
建立IServiceProvider
,用于解决奥尔良内部粮食问题。IServiceCollection
应用程序的谷物&服务,让我们说使用SimpleInjector和per-object-graph生活方式。IServiceProvider
进行解析的IServiceProvider
,如果使用基于IServiceProvider
的应用程序解析失败,则 IServiceProvider
类只需要在其中匹配此签名的方法:
Startup
此代码段public IServiceProvider ConfigureServices(IServiceCollection services)
{
return services.BuildServiceProvider();
}
由Microsoft提供.Extensions.DependencyInjection
答案 1 :(得分:0)
有一个更详细的解释:
http://www.codeproject.com/Articles/1099750/How-to-implement-DI-support-in-your-Orleans-Silo
了解您必须在奥尔良的配置文件中设置启动类非常重要。
private void EncryptFile(string inputFile, string outputFile)
{
try
{
string password = @"myKey123"; // Your Key Here
UnicodeEncoding UE = new UnicodeEncoding();
byte[] key = UE.GetBytes(password);
string cryptFile = outputFile;
FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create);
RijndaelManaged RMCrypto = new RijndaelManaged();
CryptoStream cs = new CryptoStream(fsCrypt,
RMCrypto.CreateEncryptor(key, key),
CryptoStreamMode.Write);
FileStream fsIn = new FileStream(inputFile, FileMode.Open);
int data;
while ((data = fsIn.ReadByte()) != -1)
cs.WriteByte((byte)data);
fsIn.Close();
cs.Close();
fsCrypt.Close();
}
catch(Exception ex)
{
// MessageBox.Show("Encryption failed!", "Error");
}
}
private void DecryptFile(string inputFile, string outputFile)
{
{
string password = @"myKey123"; // Your Key Here
UnicodeEncoding UE = new UnicodeEncoding();
byte[] key = UE.GetBytes(password);
FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);
RijndaelManaged RMCrypto = new RijndaelManaged();
CryptoStream cs = new CryptoStream(fsCrypt,
RMCrypto.CreateDecryptor(key, key),
CryptoStreamMode.Read);
FileStream fsOut = new FileStream(outputFile, FileMode.Create);
int data;
while ((data = cs.ReadByte()) != -1)
fsOut.WriteByte((byte)data);
fsOut.Close();
cs.Close();
fsCrypt.Close();
}
}