本文整理汇总了C#中ServiceName.AddContracts方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceName.AddContracts方法的具体用法?C# ServiceName.AddContracts怎么用?C# ServiceName.AddContracts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceName
的用法示例。
在下文中一共展示了ServiceName.AddContracts方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolveCore
internal ContainerService ResolveCore(ServiceName name, bool createNew, IObjectAccessor arguments, ResolutionContext context)
{
var pushedContracts = context.Contracts.Push(name.Contracts);
var declaredName = new ServiceName(name.Type, context.Contracts.Snapshot());
if (context.HasCycle(declaredName))
{
var message = string.Format("cyclic dependency for service [{0}], stack\r\n{1}",
declaredName.Type.FormatName(), context.FormatStack() + "\r\n\t" + declaredName);
context.Contracts.RemoveLast(pushedContracts.pushedContractsCount);
return ContainerService.Error(declaredName, message);
}
if (!pushedContracts.isOk)
{
const string messageFormat = "contract [{0}] already declared, stack\r\n{1}";
var message = string.Format(messageFormat, pushedContracts.duplicatedContractName,
context.FormatStack() + "\r\n\t" + name);
context.Contracts.RemoveLast(pushedContracts.pushedContractsCount);
return ContainerService.Error(name, message);
}
context.ConstructingServices.Add(declaredName);
ServiceConfiguration configuration = null;
Exception configurationException = null;
try
{
configuration = GetConfiguration(declaredName.Type, context);
}
catch (Exception e)
{
configurationException = e;
}
var actualName = configuration != null && configuration.FactoryDependsOnTarget && context.Stack.Count > 0
? declaredName.AddContracts(context.TopBuilder.Type.FormatName())
: declaredName;
ContainerServiceId id = null;
if (!createNew)
{
id = instanceCache.GetOrAdd(actualName, createId);
var acquireResult = id.AcquireInstantiateLock();
if (!acquireResult.acquired)
{
context.ConstructingServices.Remove(declaredName);
context.Contracts.RemoveLast(pushedContracts.pushedContractsCount);
return acquireResult.alreadyConstructedService;
}
}
var builder = new ContainerService.Builder(actualName);
context.Stack.Add(builder);
builder.Context = context;
builder.DeclaredContracts = actualName.Contracts;
if (configuration == null)
builder.SetError(configurationException);
else
{
builder.SetConfiguration(configuration);
builder.ExpandedUnions = context.Contracts.TryExpandUnions(Configuration);
if (builder.ExpandedUnions.HasValue)
{
var poppedContracts = context.Contracts.PopMany(builder.ExpandedUnions.Value.contracts.Length);
foreach (var c in builder.ExpandedUnions.Value.contracts.CartesianProduct())
{
var childService = ResolveCore(new ServiceName(name.Type, c), createNew, arguments, context);
builder.LinkTo(containerContext, childService, null);
if (builder.Status.IsBad())
break;
}
context.Contracts.PushNoCheck(poppedContracts);
}
else
{
builder.CreateNew = createNew;
builder.Arguments = arguments;
Instantiate(builder);
}
}
context.ConstructingServices.Remove(declaredName);
context.Contracts.RemoveLast(pushedContracts.pushedContractsCount);
context.Stack.RemoveLast();
var result = builder.GetService();
if (id != null)
id.ReleaseInstantiateLock(builder.Context.AnalizeDependenciesOnly ? null : result);
return result;
}