ExecuteMarketOrderResponceMessage Receive(ExecuteMarketOrderMessage message) { IImplementation implementation = _implementation; if (implementation == null || OperationalState != OperationalStateEnum.Operational) { return(new ExecuteMarketOrderResponceMessage(message.AccountInfo, null, false)); } string operationResultMessage; if (message.PerformSynchronous == false) { return(new ExecuteMarketOrderResponceMessage(message.AccountInfo, null, true)); } OrderInfo?info; if (implementation.ExecuteMarketOrder(message.AccountInfo, message.Symbol, message.OrderType, message.Volume, message.Slippage, message.DesiredPrice, message.TakeProfit, message.StopLoss, message.Comment, out info, out operationResultMessage) == false) { return(new ExecuteMarketOrderResponceMessage(message.AccountInfo, null, false) { OperationResultMessage = operationResultMessage }); } return(new ExecuteMarketOrderResponceMessage(message.AccountInfo, info, true)); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> /// <param name="implementation">Implementation</param> /// <param name="flags">Flags</param> /// <param name="offset">Offset</param> public ManifestResourceUser(UTF8String name, IImplementation implementation, ManifestResourceAttributes flags, uint offset) { this.name = name; this.implementation = implementation; this.attributes = (int)flags; this.offset = offset; }
AccountResponceMessage Receive(ModifyOrderMessage message) { IImplementation implementation = _implementation; if (implementation == null || OperationalState != OperationalStateEnum.Operational) { return(new AccountResponceMessage(message.AccountInfo, false)); } string modifiedId, operationResultMessage; ModifyOrderResponceMessage responce; if (implementation.ModifyOrder(message.AccountInfo, message.OrderId, message.StopLoss, message.TakeProfit, message.TargetOpenPrice, out modifiedId, out operationResultMessage)) { responce = new ModifyOrderResponceMessage(message.AccountInfo, message.OrderId, modifiedId, true); } else { responce = new ModifyOrderResponceMessage(message.AccountInfo, message.OrderId, modifiedId, false); } responce.ResultMessage = operationResultMessage; return(responce); }
AccountResponceMessage Receive(CloseOrderVolumeMessage message) { IImplementation implementation = _implementation; if (implementation == null || OperationalState != OperationalStateEnum.Operational) { return(new AccountResponceMessage(message.AccountInfo, false)); } decimal closingPrice; DateTime closingTime; string modifiedId; string operationResultMessage; CloseOrderVolumeResponceMessage responce; if (implementation.CloseOrCancelOrder(message.AccountInfo, message.OrderId, message.OrderTag, message.Slippage, message.Price, out closingPrice, out closingTime, out modifiedId, out operationResultMessage)) { responce = new CloseOrderVolumeResponceMessage(message.AccountInfo, message.OrderId, modifiedId, closingPrice, closingTime, true); } else { responce = new CloseOrderVolumeResponceMessage(message.AccountInfo, message.OrderId, string.Empty, decimal.Zero, DateTime.MinValue, false); } responce.ResultMessage = operationResultMessage; return(responce); }
SearchResult(IImplementation feature, ConversionPath converterPath) : base(_nextObjectId++) { Feature = feature; ConverterPath = converterPath; StopByObjectIds(); }
AccountResponceMessage Receive(AccountInformationMessage message) { IImplementation implementation = _implementation; if (implementation != null && OperationalState == OperationalStateEnum.Operational) { AccountInfo?updatedInfo = implementation.GetAccountInfoUpdate(message.AccountInfo); if (updatedInfo.HasValue) { if (message.RequestResponce) { return(new AccountResponceMessage(updatedInfo.Value, true)); } else { SendResponding(message.TransportInfo, new AccountResponceMessage(updatedInfo.Value, true)); } } } if (message.RequestResponce) { return(new AccountResponceMessage(message.AccountInfo, false)); } else { return(null); } }
/// <summary> /// Creates a new exported type reference. /// </summary> /// <param name="implementation">The file containing the type.</param> /// <param name="ns">The namespace of the type.</param> /// <param name="name">The name of the type.</param> public ExportedType(IImplementation implementation, string ns, string name) : this(new MetadataToken(TableIndex.ExportedType, 1)) { Implementation = implementation; Namespace = ns; Name = name; }
public bool HasDescendent(IImplementation query) { if (query == this.Implementation) { return(true); } Dictionary <ProjectModule, bool> visited = new Dictionary <ProjectModule, bool>(); Queue <ProjectModule> toVisit = new Queue <ProjectModule>(); toVisit.Enqueue(this); visited[this] = true; while (toVisit.Count > 0) { ProjectModule cur = toVisit.Dequeue(); foreach (ModuleComponent comp in cur.Implementation.GetModuleComponents()) { ProjectModule sub = comp.Module; if (!visited.ContainsKey(sub)) { if (sub.Implementation == query) { return(true); } visited[sub] = true; toVisit.Enqueue(sub); } } } return(false); }
SubmitOrderResponceMessage Receive(SubmitOrderMessage message) { IImplementation implementation = _implementation; if (implementation == null || OperationalState != OperationalStateEnum.Operational) { return(new SubmitOrderResponceMessage(message.AccountInfo, string.Empty, false)); } SubmitOrderResponceMessage responce; string operationResultMessage; string id; if (message.PerformSynchronous == false) {// We need to place order synchronously. responce = new SubmitOrderResponceMessage(message.AccountInfo, string.Empty, true); } else {// Just submit the order. id = implementation.SubmitOrder(message.AccountInfo, message.Symbol, message.OrderType, message.Volume, message.Slippage, message.DesiredPrice, message.TakeProfit, message.StopLoss, message.Comment, out operationResultMessage); responce = new SubmitOrderResponceMessage(message.AccountInfo, id, string.IsNullOrEmpty(id) == false); responce.ResultMessage = operationResultMessage; } return(responce); }
/// <summary> /// Creates a new external manifest resource. /// </summary> /// <param name="name">The name of the resource</param> /// <param name="attributes">The attributes of the resource.</param> /// <param name="implementation">The location of the resource data.</param> /// <param name="offset">The offset within the file referenced by <paramref name="implementation"/> where the data starts.</param> public ManifestResource(string name, ManifestResourceAttributes attributes, IImplementation implementation, uint offset) : this(new MetadataToken(TableIndex.ManifestResource, 0)) { Name = name; Attributes = attributes; Implementation = implementation; Offset = offset; }
private void Awake() { implementation = this; DontDestroyOnLoad(this); SceneManager.activeSceneChanged += ClearAll; }
public Abstraction(Type[] implementationTypes, IImplementationCache implementationCache) { implementations = new IImplementation[implementationTypes.Length]; for (int i = 0; i < implementationTypes.Length; i++) { implementations[i] = implementationCache.GetOrCreate(implementationTypes[i]); } }
/// <summary> /// /// </summary> public bool Initialize(IImplementation implementation) { _implementation = implementation; StatusSynchronizationSource = implementation; return(true); }
public ExportedType(IImplementation implementation, uint typeDefId, string name, string @namespace, TypeAttributes attributes) : base(new MetadataToken(MetadataTokenType.ExportedType)) { Attributes = attributes; TypeDefId = typeDefId; _name = new LazyValue <string>(name); _namespace = new LazyValue <string>(@namespace); _implementation = new LazyValue <IImplementation>(implementation); }
public static SearchResult Create(IImplementation feature, TypeBase definingItem) { var searchResult = feature as SearchResult; if(searchResult == null) return new SearchResult(feature, definingItem); var source = searchResult.Source; Tracer.Assert(source == definingItem); return searchResult; }
public void AddService(IDependency dependency, IImplementation implementation) { if (!_entries.ContainsKey(dependency)) { _entries[dependency] = new ConcurrentBag <IImplementation>(); } _entries[dependency].Add(implementation); }
/// <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); }
/// <summary> /// Constructor /// </summary> /// <param name="module">Owner module</param> /// <param name="typeDefId">TypeDef ID</param> /// <param name="typeName">Type name</param> /// <param name="typeNamespace">Type namespace</param> /// <param name="flags">Flags</param> /// <param name="implementation">Implementation</param> public ExportedTypeUser(ModuleDef module, uint typeDefId, UTF8String typeNamespace, UTF8String typeName, TypeAttributes flags, IImplementation implementation) { this.module = module; this.typeDefId = typeDefId; this.typeName = typeName; this.typeNamespace = typeNamespace; this.flags = flags; this.implementation = implementation; }
public HomeController( //IImplementation<IsolatedImplementation> isolated, IImplementation <SmartERPImplementation> smartERP, IImplementation <OracleERPImplementaion> oracleERP) { //_isolated = isolated; _smartERP = smartERP; _oracleERP = oracleERP; }
/// <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); }
GetAvailableAccountsResponceMessage Receive(GetAvailableAccountsMessage message) { IImplementation implementation = _implementation; if (implementation == null || OperationalState != OperationalStateEnum.Operational) { return(new GetAvailableAccountsResponceMessage(new AccountInfo[] { }, false)); } return(new GetAvailableAccountsResponceMessage(implementation.GetAvailableAccounts(), true)); }
internal ProjectModule(object key, String name, IImplementation implementation) { if (key == null) { throw new InvalidOperationException("key required"); } this.key = key; this.name = name; this.Implementation = implementation; this.Presentation = new DefaultPresentation(this); implementation.UpdateModule(this); }
AccountResponseMessage Receive(AccountInformationMessage message) { IImplementation implementation = _implementation; if (implementation == null || OperationalState != OperationalStateEnum.Operational) { if (message.RequestResponse) { return(new AccountResponseMessage(message.AccountInfo, false)); } else { return(null); } } AccountInfo?updatedInfo = implementation.GetAccountInfoUpdate(message.AccountInfo); if (updatedInfo.HasValue == false) {// Implementation has no knowledge of this, or does not wish to handle this, so provide info if we have any. lock (this) { if (_accounts.ContainsKey(message.AccountInfo.Id)) { updatedInfo = _accounts[message.AccountInfo.Id]; } } } if (updatedInfo.HasValue == false) { if (message.RequestResponse) { return(new AccountResponseMessage(message.AccountInfo, false)); } else { return(null); } } if (message.RequestResponse) { return(new AccountResponseMessage(updatedInfo.Value, true)); } else { SendResponding(message.TransportInfo, new AccountInformationUpdateMessage(updatedInfo.Value, true)); return(null); } }
public ProjectModule AddModule(String name, IImplementation implementation) { CheckWriteAccess(); ProjectModule found = GetModule(name); if (found != null) { throw new InvalidOperationException("module already exists by that name"); } ProjectModule toAdd = new ProjectModule(key, name, implementation); key.Project.modules.Add(toAdd); toIssue.Add(new ProjectModifiedArgs(this, ProjectModifiedArgs.ChangeTypes.ModuleAdded, toAdd)); return(toAdd); }
/// <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); }
/// <summary> /// Defines the instructions that will instantiate the singleton instance itself. /// </summary> /// <param name="dependency">The dependency that will be instantiated by the singleton.</param> /// <param name="implementation">The implementation that will instantiate the dependency.</param> /// <param name="serviceMap">The service map that contains the list of dependencies in the application.</param> /// <param name="instanceField">The field that will hold the singleton instance.</param> /// <param name="cctor">The static constructor itself.</param> /// <param name="module">The target module.</param> /// <param name="targetMethod">The target method that will instantiate the service instance.</param> protected virtual void EmitSingletonInstantiation(IDependency dependency, IImplementation implementation, IDictionary <IDependency, IImplementation> serviceMap, FieldDefinition instanceField, MethodDefinition cctor, ModuleDefinition module, MethodDefinition targetMethod) { var worker = cctor.GetILGenerator(); implementation.Emit(dependency, serviceMap, cctor); worker.Emit(OpCodes.Stsfld, instanceField); worker.Emit(OpCodes.Ret); }
public void TestCacheWorks() { IImplementation implementation = implementationCache.GetOrCreate(typeof(int)); Assert.That(implementation, Is.InstanceOf <Implementation>()); Assert.AreEqual(typeof(int), implementation.ObjectType); Assert.AreSame(implementation, implementationCache.GetOrCreate(typeof(int))); IImplementation implementationLong = implementationCache.GetOrCreate(typeof(long)); Assert.AreNotEqual(implementation, implementationLong); Assert.AreSame(implementation, implementationCache.GetOrCreate(typeof(int))); Assert.AreSame(implementationLong, implementationCache.GetOrCreate(typeof(long))); }
private void InitializeImplementation() { #if THREAD_SAFE theLock.EnterWriteLock(); try { #endif if (implementation_isInitialized) { return; } implementation = GetImplementation_NoLock(); implementation_isInitialized = true; #if THREAD_SAFE } finally { theLock.ExitWriteLock(); } #endif }
/// <summary> /// Converts this instance to a <see cref="TypeRef"/> /// </summary> /// <returns>A new <see cref="TypeRef"/> instance</returns> public TypeRef ToTypeRef() { TypeRef result = null, prev = null; var mod = module; IImplementation impl = this; for (int i = 0; i < MAX_LOOP_ITERS && impl != null; i++) { var et = impl as ExportedType; if (et != null) { var newTr = mod.UpdateRowId(new TypeRefUser(mod, et.TypeNamespace, et.TypeName)); if (result == null) { result = newTr; } if (prev != null) { prev.ResolutionScope = newTr; } prev = newTr; impl = et.Implementation; continue; } var asmRef = impl as AssemblyRef; if (asmRef != null) { // prev is never null when we're here prev.ResolutionScope = asmRef; return(result); } var file = impl as FileDef; if (file != null) { // prev is never null when we're here prev.ResolutionScope = FindModule(mod, file); return(result); } break; } return(result); }
GetDataSourceSymbolCompatibleResponceMessage Receive(GetDataSourceSymbolCompatibleMessage message) { IImplementation implementation = _implementation; if (implementation == null || OperationalState != OperationalStateEnum.Operational) { return(new GetDataSourceSymbolCompatibleResponceMessage(false)); } else { int result = implementation.IsDataSourceSymbolCompatible(message.DataSourceId, message.Symbol); return(new GetDataSourceSymbolCompatibleResponceMessage(true) { CompatibilityLevel = result }); } }
/// <summary> /// Emits a service as a singleton type. /// </summary> /// <param name="targetMethod">The <see cref="IMicroContainer.GetInstance"/> method implementation.</param> /// <param name="dependency">The dependency that will be instantiated by the container.</param> /// <param name="implementation">The implementation that will be used to instantiate the dependency.</param> /// <param name="serviceMap">The service map the contains the current application dependencies.</param> public void EmitService(MethodDefinition targetMethod, IDependency dependency, IImplementation implementation, IDictionary <IDependency, IImplementation> serviceMap) { MethodDefinition getInstanceMethod = null; var worker = targetMethod.GetILGenerator(); // Emit only one singleton per dependency and call // the singleton GetInstance() method on every subsequent emit call if (_entries.ContainsKey(dependency)) { getInstanceMethod = _entries[dependency]; worker.Emit(OpCodes.Call, getInstanceMethod); return; } var declaringType = targetMethod.DeclaringType; var module = declaringType.Module; var serviceType = dependency.ServiceType; var typeName = serviceType.Name; var singletonName = string.Format("{0}ServiceSingleton-{1}", typeName, dependency.GetHashCode()); const TypeAttributes typeAttributes = TypeAttributes.NotPublic | TypeAttributes.AutoClass | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit; var objectType = module.Import(typeof(object)); var singletonType = AddDefaultSingletonConstructor(module, singletonName, typeAttributes, objectType); var instanceField = new FieldDefinition("__instance", FieldAttributes.Assembly | FieldAttributes.InitOnly | FieldAttributes.Static, objectType); DefineNestedType(module, singletonType, instanceField, serviceMap, implementation, dependency, targetMethod); getInstanceMethod = DefineGetInstance(singletonType, worker, instanceField); worker.Emit(OpCodes.Call, getInstanceMethod); var serviceTypeRef = module.Import(serviceType); worker.Emit(OpCodes.Unbox_Any, serviceTypeRef); // Cache the singleton method _entries[dependency] = getInstanceMethod; }
/// <summary> /// Emits a service as a singleton type. /// </summary> /// <param name="targetMethod">The <see cref="IMicroContainer.GetInstance"/> method implementation.</param> /// <param name="dependency">The dependency that will be instantiated by the container.</param> /// <param name="implementation">The implementation that will be used to instantiate the dependency.</param> /// <param name="serviceMap">The service map the contains the current application dependencies.</param> public void EmitService(MethodDefinition targetMethod, IDependency dependency, IImplementation implementation, IDictionary<IDependency, IImplementation> serviceMap) { MethodDefinition getInstanceMethod = null; var worker = targetMethod.GetILGenerator(); // Emit only one singleton per dependency and call // the singleton GetInstance() method on every subsequent emit call if (_entries.ContainsKey(dependency)) { getInstanceMethod = _entries[dependency]; worker.Emit(OpCodes.Call, getInstanceMethod); return; } var declaringType = targetMethod.DeclaringType; var module = declaringType.Module; var serviceType = dependency.ServiceType; var typeName = serviceType.Name; var singletonName = string.Format("{0}ServiceSingleton-{1}", typeName, dependency.GetHashCode()); const TypeAttributes typeAttributes = TypeAttributes.NotPublic | TypeAttributes.AutoClass | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit; var objectType = module.Import(typeof(object)); var singletonType = AddDefaultSingletonConstructor(module, singletonName, typeAttributes, objectType); var instanceField = new FieldDefinition("__instance", FieldAttributes.Assembly | FieldAttributes.InitOnly | FieldAttributes.Static, objectType); DefineNestedType(module, singletonType, instanceField, serviceMap, implementation, dependency, targetMethod); getInstanceMethod = DefineGetInstance(singletonType, worker, instanceField); worker.Emit(OpCodes.Call, getInstanceMethod); var serviceTypeRef = module.Import(serviceType); worker.Emit(OpCodes.Unbox_Any, serviceTypeRef); // Cache the singleton method _entries[dependency] = getInstanceMethod; }
private uint AddImplementation(IImplementation implementation) { if (implementation is null) { return(0); } var token = implementation switch { AssemblyReference assemblyReference => GetAssemblyReferenceToken(assemblyReference), ExportedType exportedType => AddExportedType(exportedType), FileReference fileReference => AddFileReference(fileReference), _ => throw new ArgumentOutOfRangeException(nameof(implementation)) }; return(Metadata.TablesStream .GetIndexEncoder(CodedIndex.Implementation) .EncodeToken(token)); }
/// <summary> /// Defines the instructions that will instantiate the singleton instance itself. /// </summary> /// <param name="dependency">The dependency that will be instantiated by the singleton.</param> /// <param name="implementation">The implementation that will instantiate the dependency.</param> /// <param name="serviceMap">The service map that contains the list of dependencies in the application.</param> /// <param name="instanceField">The field that will hold the singleton instance.</param> /// <param name="cctor">The static constructor itself.</param> /// <param name="module">The target module.</param> /// <param name="targetMethod">The target method that will instantiate the service instance.</param> protected override void EmitSingletonInstantiation(IDependency dependency, IImplementation implementation, IDictionary <IDependency, IImplementation> serviceMap, FieldDefinition instanceField, MethodDefinition cctor, ModuleDefinition module, MethodDefinition targetMethod) { var containerType = targetMethod.DeclaringType; var containerLocal = AddContainerVariable(module, cctor); var containerConstructor = containerType.GetDefaultConstructor(); var il = cctor.GetILGenerator(); SaveContainerInstance(il, containerConstructor, containerLocal); base.EmitSingletonInstantiation(dependency, implementation, serviceMap, instanceField, cctor, module, targetMethod); ReplaceContainerCalls(cctor, containerLocal, il); }
private static IImplementation <ConstructorInfo> GetExpectedConstructorImplementation(IEnumerable <IImplementation <ConstructorInfo> > constructorImplementations) { var bestParameterCount = 0; IImplementation <ConstructorInfo> expectedImplementation = null; foreach (var implementation in constructorImplementations) { var target = implementation.Target; var parameterCount = target.GetParameters().Count(); if (expectedImplementation != null && parameterCount <= bestParameterCount) { continue; } expectedImplementation = implementation; bestParameterCount = parameterCount; } return(expectedImplementation); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> /// <param name="implementation">Implementation</param> /// <param name="flags">Flags</param> /// <param name="offset">Offset</param> public ManifestResourceUser(UTF8String name, IImplementation implementation, ManifestResourceAttributes flags, uint offset) { this.name = name; this.implementation = implementation; this.flags = flags; this.offset = offset; }
/// <summary> /// Constructor /// </summary> /// <param name="module">Owner module</param> /// <param name="typeDefId">TypeDef ID</param> /// <param name="typeName">Type name</param> /// <param name="typeNamespace">Type namespace</param> /// <param name="flags">Flags</param> /// <param name="implementation">Implementation</param> public ExportedTypeUser(ModuleDef module, uint typeDefId, UTF8String typeNamespace, UTF8String typeName, TypeAttributes flags, IImplementation implementation) { this.module = module; this.typeDefId = typeDefId; this.typeName = typeName; this.typeNamespace = typeNamespace; this.attributes = (int)flags; this.implementation = implementation; this.implementation_isInitialized = true; }
/// <summary> /// /// </summary> public bool Initialize(IImplementation implementation) { _implementation = implementation; StatusSynchronizationSource = implementation; return true; }
SearchResult(IImplementation feature, TypeBase definingItem) : this(feature, new ConversionPath(definingItem)) {}
/// <summary> /// Emits the instructions that will instantiate the target service. /// </summary> /// <param name="getInstanceMethod">The method that will instantiate the target type.</param> /// <param name="dependency">The target dependency</param> /// <param name="implementation">The implementation that will instantiate the dependency.</param> /// <param name="serviceMap">The service map that contains the list of dependencies in the application.</param> protected virtual void EmitService(MethodDefinition getInstanceMethod, IDependency dependency, IImplementation implementation, IDictionary<IDependency, IImplementation> serviceMap) { implementation.Emit(dependency, serviceMap, getInstanceMethod); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> /// <param name="implementation">Implementation</param> public ManifestResourceUser(UTF8String name, IImplementation implementation) : this(name, implementation, 0) { }
/// <summary> /// Defines the nested type that will instantiate the actual singleton service instance. /// </summary> /// <param name="module">The module that will host the singleton type.</param> /// <param name="singletonType">The singleton type.</param> /// <param name="instanceField">The field that will hold the singleton instance.</param> /// <param name="serviceMap">The service map that contains the list of dependencies in the application.</param> /// <param name="implementation">The implementation that will instantiate the dependency.</param> /// <param name="dependency">The dependency that will be instantiated by the singleton.</param> /// <param name="targetMethod">The method that will be used to instantiate the actual service instance.</param> private void DefineNestedType(ModuleDefinition module, TypeDefinition singletonType, FieldDefinition instanceField, IDictionary<IDependency, IImplementation> serviceMap, IImplementation implementation, IDependency dependency, MethodDefinition targetMethod) { var objectType = module.ImportType(typeof (object)); var nestedName = string.Format("Nested-{0}", dependency.GetHashCode()); const TypeAttributes nestedAttributes = TypeAttributes.NestedFamORAssem | TypeAttributes.Sealed | TypeAttributes.AutoClass | TypeAttributes.Class | TypeAttributes.AnsiClass; var nestedType = module.DefineClass(nestedName, "Hiro.Containers.Internal", nestedAttributes, objectType); singletonType.NestedTypes.Add(nestedType); nestedType.Fields.Add(instanceField); // Emit the static constructor body var cctor = DefineNestedConstructors(module, nestedType); EmitSingletonInstantiation(dependency, implementation, serviceMap, instanceField, cctor, module, targetMethod); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> /// <param name="implementation">Implementation</param> /// <param name="flags">Flags</param> public ManifestResourceUser(UTF8String name, IImplementation implementation, ManifestResourceAttributes flags) : this(name, implementation, flags, 0) { }
void InitializeImplementation() { #if THREAD_SAFE theLock.EnterWriteLock(); try { #endif if (implementation_isInitialized) return; implementation = GetImplementation_NoLock(); implementation_isInitialized = true; #if THREAD_SAFE } finally { theLock.ExitWriteLock(); } #endif }
/// <summary> /// Defines the instructions that will instantiate the singleton instance itself. /// </summary> /// <param name="dependency">The dependency that will be instantiated by the singleton.</param> /// <param name="implementation">The implementation that will instantiate the dependency.</param> /// <param name="serviceMap">The service map that contains the list of dependencies in the application.</param> /// <param name="instanceField">The field that will hold the singleton instance.</param> /// <param name="cctor">The static constructor itself.</param> /// <param name="module">The target module.</param> /// <param name="targetMethod">The target method that will instantiate the service instance.</param> protected virtual void EmitSingletonInstantiation(IDependency dependency, IImplementation implementation, IDictionary<IDependency, IImplementation> serviceMap, FieldDefinition instanceField, MethodDefinition cctor, ModuleDefinition module, MethodDefinition targetMethod) { var worker = cctor.GetILGenerator(); implementation.Emit(dependency, serviceMap, cctor); worker.Emit(OpCodes.Stsfld, instanceField); worker.Emit(OpCodes.Ret); }