本文整理汇总了C#中IDependency类的典型用法代码示例。如果您正苦于以下问题:C# IDependency类的具体用法?C# IDependency怎么用?C# IDependency使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IDependency类属于命名空间,在下文中一共展示了IDependency类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HomeController
public HomeController(IDependency dependency, ITenantIdentificationStrategy tenantIdStrategy, IMultitenantService standardService, IMetadataConsumer metadataService)
{
this.Dependency = dependency;
this.TenantIdentificationStrategy = tenantIdStrategy;
this.StandardServiceProxy = standardService;
this.MetadataServiceProxy = metadataService;
}
示例2: OnDependencyReady
private void OnDependencyReady(IDependency dependency)
{
dependency.Ready -= OnDependencyReady;
DependencyReadyStatus[dependency] = true;
if (DependencyReadyStatus.Values.All(status => status))
DoStart();
}
示例3: Emit
/// <summary>
/// Emits the instructions that will instantiate the current implementation using the given factory functor.
/// </summary>
/// <param name="dependency">The dependency that describes the service to be instantiated.</param>
/// <param name="serviceMap">The service map that contains the list of dependencies in the application.</param>
/// <param name="targetMethod">The target method.</param>
public void Emit(IDependency dependency,
IDictionary<IDependency, IImplementation> serviceMap,
MethodDefinition targetMethod)
{
var declaringType = targetMethod.DeclaringType;
var module = declaringType.Module;
var serviceType = module.Import(_serviceType);
var createInstanceMethod = typeof(FunctorRegistry).GetMethod("CreateInstance");
var createInstance = module.Import(createInstanceMethod);
// Register the functor
RegisterFunctor();
var body = targetMethod.Body;
var IL = body.GetILProcessor();
// Instantiate the instance at runtime using the
// given functor associated with the functor id
IL.Emit(OpCodes.Ldstr, _functorId);
IL.Emit(OpCodes.Ldarg_0);
IL.Emit(OpCodes.Call, createInstance);
if (serviceType.IsValueType)
return;
IL.Emit(OpCodes.Castclass, serviceType);
}
示例4: GetDependencyNodes
private static IEnumerable<INode> GetDependencyNodes(this TreeContext context, IDependency dep1)
{
return dep1.Type == DependencyType.Single
? new[] { context.Tree.Nodes[dep1.Token] }
: context.Tree.GetNode(dep1.Token)
.Provider.Dependencies
.SelectMany(context.GetDependencyNodes);
}
示例5: ContainerInitialized
/// <inheritdoc />
public override void ContainerInitialized(Container container)
{
base.ContainerInitialized(container);
Log.Info("ExtensionWhichNeedsDependency is using the initialized container.");
this.Dependency = this.Container.Resolve<IDependency>();
}
示例6: AddService
/// <summary>
/// Associates the given <paramref name="implementation"/> with the target <paramref name="dependency"/>.
/// </summary>
/// <param name="dependency">The dependency that will be associated with the implementation.</param>
/// <param name="implementation">The implementation itself.</param>
public void AddService(IDependency dependency, IImplementation implementation)
{
var currentImplementation = implementation;
if (Injector != null)
currentImplementation = Injector.Inject(dependency, currentImplementation);
_entries.Add(dependency, currentImplementation);
}
示例7: GetDependencyNode
// can be used after the tree is built
public static INode GetDependencyNode(this TreeContext context, IDependency dependency)
{
var node = context.Tree.GetNode(dependency.Token);
return dependency.Type == DependencyType.CollectionValidity
? node.Parent
: dependency.Type == DependencyType.Collection
? node.SourceParent
: node;
}
示例8: Constructor
public Constructor(IDependency dependency, ConstructorInfo constructor)
: base(dependency)
{
ConstructorInfo = constructor;
_requiredDependencies = constructor.GetParameters()
.Select(p => new Dependency(p.ParameterType))
.ToArray();
}
示例9: SetNodeWeights
private static void SetNodeWeights(TreeContext context, IDependency dependency, IDependency dep2)
{
if (context.IsParent(dependency.Token, dep2.Token) || context.IsParent(dep2.Token, dependency.Token))
{
return;
}
SetNodeWeights(context, dependency);
SetNodeWeights(context, dep2);
}
示例10: TflRoot
public TflRoot(
string cfg,
Dictionary<string, string> parameters = null,
IDependency logger = null)
: base(
new DefaultReader(new SourceDetector(), new FileReader(), new ReTryingReader(new WebReader(), 3)),
logger
) {
Load(cfg, parameters);
}
示例11: GenericTypeInstantiation
public GenericTypeInstantiation(IDependency dependency, Constructor constructor, IEnumerable<Type> typeArguments) : base(dependency)
{
if (dependency == null)
throw new ArgumentNullException(nameof(dependency));
if (constructor == null)
throw new ArgumentNullException(nameof(constructor));
Constructor = constructor;
TypeArguments = typeArguments;
}
示例12: Emit
/// <summary>
/// Emits the instructions that will instantiate the current implementation.
/// </summary>
/// <param name="dependency">The dependency that describes the service to be instantiated.</param>
/// <param name="serviceMap">The service map that contains the list of dependencies in the application.</param>
/// <param name="targetMethod">The target method.</param>
public void Emit(IDependency dependency, IDictionary<IDependency, IImplementation> serviceMap, MethodDefinition targetMethod)
{
var declaringType = targetMethod.DeclaringType;
var module = declaringType.Module;
var microContainerType = module.ImportType<IMicroContainer>();
var il = targetMethod.GetILGenerator();
// if (this is IMicroContainer && this.NextContainer != null) {
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Isinst, microContainerType);
var skipCreate = il.Create(OpCodes.Nop);
il.Emit(OpCodes.Brfalse, skipCreate);
EmitGetContainerInstance(module, microContainerType, il, skipCreate);
var getInstance = module.ImportMethod<IMicroContainer>("GetInstance");
var getTypeFromHandleMethod = typeof(System.Type).GetMethod("GetTypeFromHandle", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
var getTypeFromHandle = module.Import(getTypeFromHandleMethod);
// Push the service type onto the stack
var serviceType = module.Import(_serviceType);
il.Emit(OpCodes.Ldtoken, serviceType);
il.Emit(OpCodes.Call, getTypeFromHandle);
var loadString = string.IsNullOrEmpty(_serviceName)
? il.Create(OpCodes.Ldnull)
: il.Create(OpCodes.Ldstr, _serviceName);
il.Append(loadString);
il.Emit(OpCodes.Callvirt, getInstance);
var endLabel = il.Create(OpCodes.Nop);
il.Emit(OpCodes.Br, endLabel);
il.Append(skipCreate);
var serviceNotFoundExceptionCtor = module.ImportConstructor<ServiceNotFoundException>(typeof(string),
typeof(System.Type));
var serviceName = dependency.ServiceName ?? string.Empty;
il.Emit(OpCodes.Ldstr, serviceName);
il.Emit(OpCodes.Ldtoken, serviceType);
il.Emit(OpCodes.Call, getTypeFromHandle);
il.Emit(OpCodes.Newobj, serviceNotFoundExceptionCtor);
il.Emit(OpCodes.Throw);
il.Append(endLabel);
// }
}
示例13: CompareTo
public int CompareTo(IDependency other)
{
var areEqual = (other.Name == this.Name && other.DependencyType == this.DependencyType);
if (areEqual)
return 0;
var otherHash = other.GetHashCode();
var thisHash = this.GetHashCode();
var isGreater = otherHash > thisHash;
return isGreater ? 1 : -1;
}
示例14: ReorderNodes
public static void ReorderNodes(this TreeContext context,
IDepend depend,
IDependency dependency1,
IDependency dependency2)
{
var node1 = context.GetDependencyNode(dependency1);
var node2 = context.GetDependencyNode(dependency2);
if (node1 == node2)
{
return;
}
ReorderNodes(node1, node2, depend.DiagInfo);
context.CreateNonEqualFilter(node1, node2, context.GetParentGroup(depend), depend.DiagInfo);
}
示例15: Inject
/// <summary>
/// Injects the target <paramref name="IImplementation"/> instance.
/// </summary>
/// <param name="dependency">The target dependency.</param>
/// <param name="originalImplementation">The target implementation that will be intercepted by this method.</param>
/// <returns>The <see cref="IImplementation"/> instance that will be injected in place of the original implementation.</returns>
public IImplementation Inject(IDependency dependency, IImplementation originalImplementation)
{
var staticImplementation = originalImplementation as IStaticImplementation;
// HACK: Ignore primitive types by default
var serviceType = dependency.ServiceType;
if (serviceType.IsValueType || serviceType==typeof(string))
return originalImplementation;
// Property injection can only be performend on early-bound instantiations
if (staticImplementation == null)
return originalImplementation;
return new PropertyInjectionCall(staticImplementation);
}