public AutoMockedContainer(ServiceLocator locator) { _locator = locator; onMissingFactory = delegate(Type pluginType, ProfileManager profileManager) { //Modified to inject concrete classes that have virtual methods if (!pluginType.IsAbstract && pluginType.IsClass && !pluginType.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).Where(p => p.IsVirtual).Any()) { return null; } var factory = new InstanceFactory(new PluginFamily(pluginType)); try { object service = _locator.Service(pluginType); var instance = new ObjectInstance(service); profileManager.SetDefault(pluginType, instance); } catch (Exception) { // ignore errors } return factory; }; }
public AutoMockedContainer(ServiceLocator locator) { _locator = locator; onMissingFactory = delegate(Type pluginType, ProfileManager profileManager) { if (!pluginType.IsAbstract && pluginType.IsClass) { return null; } var factory = new InstanceFactory(new PluginFamily(pluginType)); try { object service = _locator.Service(pluginType); var instance = new ObjectInstance(service); profileManager.SetDefault(pluginType, instance); } catch (Exception) { // ignore errors } return factory; }; }
public void returns_missing_instance_if_it_exists_and_the_requested_instance_is_not_found() { var factory = new InstanceFactory(typeof (IWidget)); var missing = new ObjectInstance(new AWidget()); factory.MissingInstance = missing; factory.FindInstance("anything").ShouldBeTheSameAs(missing); factory.FindInstance(Guid.NewGuid().ToString()).ShouldBeTheSameAs(missing); }
public void import_from_another_family_will_override_the_build_policy_if_the_initial_policy_is_the_default() { var factory = new InstanceFactory(typeof (IWidget)); var family = new PluginFamily(typeof (IWidget)); family.SetScopeTo(InstanceScope.Singleton); factory.ImportFrom(family); factory.Lifecycle.ShouldBeOfType<SingletonLifecycle>(); }
public void do_not_replace_the_build_Lifecycle_if_it_is_the_same_type_as_the_imported_family() { var originalFamily = new PluginFamily(typeof (IWidget)); originalFamily.SetScopeTo(InstanceScope.Singleton); var factory = new InstanceFactory(originalFamily); ILifecycle originalLifecycle = factory.Lifecycle; var family = new PluginFamily(typeof (IWidget)); family.SetScopeTo(InstanceScope.Singleton); factory.ImportFrom(family); factory.Lifecycle.ShouldBeTheSameAs(originalLifecycle); }
public void eject_all_instances_removes_all_instances_and_ejects_from_the_build_policy() { var factory = new InstanceFactory(typeof (IGateway)); factory.AddInstance(new SmartInstance<DefaultGateway>()); factory.AddInstance(new SmartInstance<DefaultGateway>()); var lifecycle = MockRepository.GenerateMock<ILifecycle>(); factory.Lifecycle = lifecycle; factory.EjectAllInstances(); factory.AllInstances.Count().ShouldEqual(0); lifecycle.AssertWasCalled(x => x.EjectAll()); }
public void Import_from_family_picks_up_new_instances() { var factory = new InstanceFactory(typeof (IWidget)); var family = new PluginFamily(typeof (IWidget)); family.AddInstance(new ObjectInstance(new AWidget()).WithName("New")); family.AddInstance(new ObjectInstance(new AWidget()).WithName("New2")); family.AddInstance(new ObjectInstance(new AWidget()).WithName("New3")); factory.ImportFrom(family); Assert.IsNotNull(factory.FindInstance("New")); Assert.IsNotNull(factory.FindInstance("New2")); Assert.IsNotNull(factory.FindInstance("New3")); }
public ConferenceView() { _iConferenceService = InstanceFactory.GetInstance <DapperConferenceDal>(); InitializeComponent(); DataContext = new conference(); }
public void SetUp() { factory = new InstanceFactory(typeof (IGateway)); factory.AddInstance(new SmartInstance<DefaultGateway>()); factory.AddInstance(new SmartInstance<DefaultGateway>()); var lifecycle = MockRepository.GenerateMock<ILifecycle>(); factory.Lifecycle = lifecycle; factory.MissingInstance = new SmartInstance<DefaultGateway>(); clone = factory.Clone(); }
public FrmUrunYeni() { InitializeComponent(); _urunService = InstanceFactory.GetInstance <IUrunService>(); _stokService = InstanceFactory.GetInstance <IStokService>(); }
// GET: Admin public AdminController() { _companyApplyDal = InstanceFactory.GetInstance <ICompanyApplyDal>(); }
private static ISettings GetSettingsInstance() { return(InstanceFactory.CreateSettingsInstance()); }
public CustomerOperations() { InitializeComponent(); _userService = InstanceFactory.GetInstance <IUserService>(); _customerService = InstanceFactory.GetInstance <ICustomerService>(); }
public static object DeserializeObject(StreamReader sr, Type type, InstanceFactory factory = null) { var dserResult = Deserialize(sr); return(PopulateObject(dserResult, type, "/", factory)); }
public ArizaListesiForm() { InitializeComponent(); arizaServis = InstanceFactory.Get<IArizaDetayService>(); urunKabulServis = InstanceFactory.Get<IUrunKabulService>(); }
private static void DependencyInjection() { InstanceFactory.RegisterTransient <ISeedService, SeedService>(); InstanceFactory.RegisterTransient <IDealData, DealData>(); }
public void Instantiate_DerivedFromMain_Success() { var resolver = new Mock <ISequenceResolver>(); resolver.Setup(x => x.Execute()).Returns(new[] { "BE_20190101", "BE_20190102", "BE_20190103", "BE_20190104", "BE_20190105" }); var firstTransformation = new NativeTransformer <string>(new ServiceLocator(), null);; firstTransformation.Initialize("text-to-first-chars(2)"); var secondTransformation = new NativeTransformer <string>(new ServiceLocator(), null);; secondTransformation.Initialize("text-to-last-chars(8) | text-to-dateTime(yyyyMMdd)"); var thirdTransformation = new NativeTransformer <DateTime>(new ServiceLocator(), null);; thirdTransformation.Initialize("dateTime-to-add(7)"); var args = new DerivedVariableInstanceArgs() { Name = "main", Resolver = resolver.Object, Derivations = new Dictionary <string, DerivationArgs>() { { "first", new DerivationArgs() { Source = "main", Transformer = firstTransformation } }, { "second", new DerivationArgs() { Source = "main", Transformer = secondTransformation } }, { "third", new DerivationArgs() { Source = "second", Transformer = thirdTransformation } } } }; var factory = new InstanceFactory(); var instances = factory.Instantiate(args); Assert.That(instances.Count, Is.EqualTo(5)); Assert.That(instances.ElementAt(0).Variables.Count, Is.EqualTo(4)); Assert.That(instances.ElementAt(0).Variables.ContainsKey("main"), Is.True); Assert.That(instances.ElementAt(0).Variables["main"].GetValue(), Is.EqualTo("BE_20190101")); Assert.That(instances.ElementAt(0).Variables.ContainsKey("first"), Is.True); Assert.That(instances.ElementAt(0).Variables["first"].GetValue(), Is.EqualTo("BE")); Assert.That(instances.ElementAt(0).Variables.ContainsKey("second"), Is.True); Assert.That(instances.ElementAt(0).Variables["second"].GetValue(), Is.EqualTo(new DateTime(2019, 1, 1))); Assert.That(instances.ElementAt(0).Variables.ContainsKey("third"), Is.True); Assert.That(instances.ElementAt(0).Variables["third"].GetValue(), Is.EqualTo(new DateTime(2019, 1, 8))); Assert.That(instances.ElementAt(1).Variables.Count, Is.EqualTo(4)); Assert.That(instances.ElementAt(1).Variables.ContainsKey("main"), Is.True); Assert.That(instances.ElementAt(1).Variables["main"].GetValue(), Is.EqualTo("BE_20190102")); Assert.That(instances.ElementAt(1).Variables.ContainsKey("first"), Is.True); Assert.That(instances.ElementAt(1).Variables["first"].GetValue(), Is.EqualTo("BE")); Assert.That(instances.ElementAt(1).Variables.ContainsKey("second"), Is.True); Assert.That(instances.ElementAt(1).Variables["second"].GetValue(), Is.EqualTo(new DateTime(2019, 1, 2))); Assert.That(instances.ElementAt(1).Variables.ContainsKey("third"), Is.True); Assert.That(instances.ElementAt(1).Variables["third"].GetValue(), Is.EqualTo(new DateTime(2019, 1, 9))); }
public StudentManager(IStudentDal studentDal) { _studentDal = studentDal; _departmentRecordService = InstanceFactory.GetInstance <IDepartmentRecordService>(); _lessonRecordService = InstanceFactory.GetInstance <ILessonRecordService>(); }
public Form1() { InitializeComponent(); _bookService = InstanceFactory.GetInstance <IBookService>(); _authorService = InstanceFactory.GetInstance <IAuthorService>(); }
public YorumController() { yorumService = InstanceFactory.GetInstance <IYorumService>(); }
/// <summary> /// Processes the given <see cref="IGraphFieldRequest" /> against this instance /// performing the operation as defined by this entity and generating a response. /// </summary> /// <param name="context">The field context containing the necessary data to resolve /// the field and produce a reslt.</param> /// <param name="cancelToken">The cancel token monitoring the execution of a graph request.</param> /// <returns>Task<IGraphPipelineResponse>.</returns> public async Task Resolve(FieldResolutionContext context, CancellationToken cancelToken = default) { var sourceData = context.Arguments.SourceData; if (sourceData == null) { context.Messages.Critical( "No source data was provided to the field resolver " + $"for '{_graphMethod.Name}'. Unable to complete the request.", Constants.ErrorCodes.INVALID_OBJECT, context.Request.Origin); return; } // valdidate the incoming source data to ensure its process-able by this property // resolver. If the data is being resolved through an interface or object reference // ensure the provided // source data can be converted otherwise ensure the types match exactly. if (_graphMethod.Parent.ObjectType.IsInterface || _graphMethod.Parent.ObjectType.IsClass) { if (!Validation.IsCastable(sourceData.GetType(), _graphMethod.Parent.ObjectType)) { context.Messages.Critical( "The source data provided to the field resolver " + $"for '{_graphMethod.Route.Path}' could not be coerced into the expected source graph type. See exception for details.", Constants.ErrorCodes.INVALID_OBJECT, context.Request.Origin, new GraphExecutionException( $"The property '{_graphMethod.InternalFullName}' expected source data that implements the interface " + $"'{_graphMethod.Parent.ObjectType.FriendlyName()}' but received '{sourceData.GetType().FriendlyName()}' which " + "is not compatible.")); return; } } else if (sourceData.GetType() != _graphMethod.Parent.ObjectType) { context.Messages.Critical( "The source data provided to the field resolver " + $"for '{_graphMethod.Route.Path}' could not be coerced into the expected source graph type. See exception for details.", Constants.ErrorCodes.INVALID_OBJECT, context.Request.Origin, new GraphExecutionException( $"The property '{_graphMethod.InternalFullName}' expected source data of type " + $"'{_graphMethod.Parent.ObjectType.FriendlyName()}' but received '{sourceData.GetType().FriendlyName()}' " + "which is not compatible.")); return; } try { var invoker = InstanceFactory.CreateInstanceMethodInvoker(_graphMethod.Method); var invokeReturn = invoker(sourceData, new object[0]); if (_graphMethod.IsAsyncField) { if (invokeReturn is Task task) { await task.ConfigureAwait(false); if (task.IsFaulted) { throw task.UnwrapException(); } invokeReturn = task.ResultOfTypeOrNull(_graphMethod.ExpectedReturnType); } else { context.Messages.Critical( "The source data provided to the field resolver " + $"for '{_graphMethod.Route.Path}' could not be coerced into the expected source graph type. See exception for details.", Constants.ErrorCodes.INVALID_OBJECT, context.Request.Origin, new GraphExecutionException( $"The method '{_graphMethod.Route.Path}' is defined " + $"as asyncronous but it did not return a {typeof(Task)}.")); invokeReturn = null; } } context.Result = invokeReturn; } catch (Exception ex) { context.Messages.Critical( $"An unknown error occured atttempting to resolve the field '{_graphMethod.Route.Path}'. See exception for details.", Constants.ErrorCodes.UNHANDLED_EXCEPTION, context.Request.Origin, ex); } }
public void RegistrationTest_Ok() { var regData = InstanceFactory.RegistrationData(); AuthorizationService.RegisterMember(regData); }
public WebView() { this.InitializeComponent(); DataContext = InstanceFactory.GetInstance <IWebViewModel>(); }
public void UsernameAvailable_Ok() { Assert.IsTrue(AuthorizationService.IsUsernameAvailable(InstanceFactory.GenerateString())); }
public FrmGiderlerYeni() { InitializeComponent(); _giderService = InstanceFactory.GetInstance <IGiderService>(); }
public static object DeserializeObject(string sourceString, Type type, InstanceFactory factory = null) { var dserResult = Deserialize(sourceString); return(PopulateObject(dserResult, type, "/", factory)); }
public HomeController() { haberServis = InstanceFactory.GetInstance <IHaberService>(); }
private static object PopulateObject(JToken root, Type type, string path, InstanceFactory factory) { if (root is JObject) { object instance = null; if (type == null) { instance = factory(path, null, -1); type = instance.GetType(); } if (instance == null) { instance = AppDomain.CurrentDomain.CreateInstanceAndUnwrap(type.Assembly.FullName, type.FullName); } if (instance == null) { throw new Exception("failed to create target instance"); } var jobj = (JObject)root; foreach (var item in jobj.Members) { var prop = (JProperty)item; MethodInfo method = null; Type itemType = null; var field = type.GetField(prop.Name); if (field != null) { itemType = field.FieldType; } else { method = type.GetMethod("get_" + prop.Name); itemType = method.ReturnType; method = type.GetMethod("set_" + prop.Name); } if (itemType != null) { if (prop.Value is JObject) { var childpath = path; if (childpath[childpath.Length - 1] != '/') { childpath = childpath + '/' + prop.Name; } else { childpath += prop.Name; } var child = PopulateObject(prop.Value, itemType, childpath, factory); if (field != null) { field.SetValue(instance, child); } else { method.Invoke(instance, new object[] { child }); } } else if (prop.Value is JValue) { if (field != null) { if (itemType != typeof(DateTime)) { field.SetValue(instance, ((JValue)prop.Value).Value); } else { DateTime dt; var sdtValue = ((JValue)prop.Value).Value; if (sdtValue is DateTime) { dt = (DateTime)sdtValue; } else { var sdt = sdtValue.ToString(); if (sdt.Contains("Date(")) { dt = DateTimeExtensions.FromASPNetAjax(sdt); } else { dt = DateTimeExtensions.FromIso8601(sdt); } } field.SetValue(instance, dt); } } else { if (itemType != typeof(DateTime)) { method.Invoke(instance, new object[] { ((JValue)prop.Value).Value }); } else { DateTime dt; var sdt = ((JValue)prop.Value).Value.ToString(); if (sdt.Contains("Date(")) { dt = DateTimeExtensions.FromASPNetAjax(sdt); } else { dt = DateTimeExtensions.FromIso8601(sdt); } method.Invoke(instance, new object[] { dt }); } } } else if (prop.Value is JArray) { if (factory == null) { throw new NotSupportedException("You must provide an instance factory if you want to populate objects that have arrays in them"); } var jarray = (JArray)prop.Value; var list = new ArrayList(); var array = (Array)factory(path, prop.Name, jarray.Length); //var array = Array.CreateInstance(field.FieldType.GetElementType(), jarray.Length); foreach (var elem in jarray.Items) { if (elem is JValue) { list.Add(((JValue)elem).Value); } else { var arrayObj = PopulateObject(elem, null, path + "/" + prop.Name, factory); list.Add(arrayObj); } } list.CopyTo(array); if (field != null) { field.SetValue(instance, array); } else { method.Invoke(instance, new object[] { array }); } } } } return(instance); } else if (root is JArray) { var elemType = type.GetElementType(); if (elemType == null && factory == null) { throw new NotSupportedException("You must provide an instance factory if you want to populate objects that have arrays in them"); } var jarray = (JArray)root; var list = new ArrayList(); Array array; if (elemType != null) { array = Array.CreateInstance(type.GetElementType(), jarray.Length); } else { array = (Array)factory(path, null, jarray.Length); } foreach (var item in jarray.Items) { if (item is JValue) { list.Add(((JValue)item).Value); } else { var arrayObj = PopulateObject(item, null, path, factory); list.Add(arrayObj); } } list.CopyTo(array); return(array); } return(null); }
//protected MultiInstanceFactory MultiInstanceFactory { get; } public ServiceLocator(InstanceFactory instanceFactory) //, MultiInstanceFactory multiInstanceFactory) { SingleInstanceFactory = instanceFactory; //MultiInstanceFactory = multiInstanceFactory; }
public Form1() { InitializeComponent(); _productService = InstanceFactory.GetInstance <IProductService>(); _categoryService = InstanceFactory.GetInstance <ICategoryService>(); }
public SignUpPage() { InitializeComponent(); _userService = InstanceFactory.GetInstance <IUserService>(); }
void Awake() { if (instance == null) instance = this; else if (instance != null) Destroy(gameObject); }
/// <summary> /// Using the child context being invoked, this method creates the execution contexts in a manner /// that is expected by the invocation context be that 1 per each item, or 1 for a collective set of items being batched. /// </summary> /// <param name="context">The context.</param> /// <param name="childInvocationContext">The child invocation context.</param> /// <param name="sourceItemsToInclude">The source items to include.</param> /// <returns>IEnumerable<GraphFieldExecutionContext>.</returns> private IEnumerable <GraphFieldExecutionContext> CreateChildExecutionContexts( GraphFieldExecutionContext context, IGraphFieldInvocationContext childInvocationContext, IEnumerable <GraphDataItem> sourceItemsToInclude) { if (childInvocationContext.Field.Mode == FieldResolutionMode.PerSourceItem) { foreach (var sourceItem in sourceItemsToInclude) { var child = sourceItem.AddChildField(childInvocationContext); var dataSource = new GraphFieldDataSource(sourceItem.ResultData, child.Origin.Path, child); var request = new GraphFieldRequest(childInvocationContext, dataSource, child.Origin, context.Request.Items); yield return(new GraphFieldExecutionContext(context, request, context.VariableData)); } } else if (childInvocationContext.Field.Mode == FieldResolutionMode.Batch) { // remove any potential indexers from the path to this batch operation // in general this will be acted on a collection of items, attempt to remove // the first found instance of an indexer in the chain to indicate the path to the batch // // items may be declared as: Top.Parent[0].BatchField, Top.Parent[1].BatchField // alter the canonical path to be: Top.Parent.BatchField var fieldPath = sourceItemsToInclude.First().Origin.Path.Clone(); while (fieldPath.IsIndexedItem) { fieldPath = fieldPath.MakeParent(); } fieldPath.AddFieldName(childInvocationContext.Field.Name); var batchOrigin = new SourceOrigin(context.Request.Origin.Location, fieldPath); // create a list to house the raw source data being passed for the batch // this is the IEnumerable<T> required as an input to any batch resolver var sourceArgumentType = childInvocationContext.Field.Arguments.SourceDataArgument?.ObjectType ?? typeof(object); var sourceListType = typeof(List <>).MakeGenericType(sourceArgumentType); var sourceDataList = InstanceFactory.CreateInstance(sourceListType) as IList; // create a list of all the GraphDataItems representing the field // being resolved per input item var sourceItemList = new List <GraphDataItem>(); foreach (var item in sourceItemsToInclude) { var childField = item.AddChildField(childInvocationContext); sourceDataList.Add(item.ResultData); sourceItemList.Add(childField); } var dataSource = new GraphFieldDataSource( sourceDataList, fieldPath, sourceItemList); var request = new GraphFieldRequest(childInvocationContext, dataSource, batchOrigin, context.Request.Items); yield return(new GraphFieldExecutionContext(context, request, context.VariableData)); } else { throw new ArgumentOutOfRangeException( nameof(childInvocationContext.Field.Mode), $"The execution mode for field '{childInvocationContext.Field.Route.Path}' cannot be processed " + $"by {nameof(ProcessChildFieldsMiddleware<TSchema>)}. (Mode: {childInvocationContext.Field.Mode.ToString()})"); } }
public AnasayfaForm() { InitializeComponent(); _musteriServis = InstanceFactory.GetInstance <IMusteriService>(); }
public Login() { userService = InstanceFactory.GetInstance <IUserService>(); InitializeComponent(); }
public bool TryGetInstanceFactory(Type type, out InstanceFactory factory) { factory = Factories.Array.FirstOrDefault(x => x.DependencyType == type); return(factory != null); }
public void DrawChart() { if (_IPositionStatisticsBarChartView.gvPositionStatisticsSource == null) { IEmployeeSalaryStatisticsFacade _IEmployeeSalaryStatisticsFacade = InstanceFactory.CreateEmployeeSalaryStatisticsFacade(); List <Model.PayModule.EmployeeSalaryStatistics> employeeSalaryStatistics = _IEmployeeSalaryStatisticsFacade.PositionStatistics( Convert.ToDateTime(_IStatisticsConditionView.FromDate), Convert.ToDateTime(_IStatisticsConditionView.ToDate), _IStatisticsConditionView.DepartmentID, _IStatisticsConditionView.SelectedAccountSetPara, _IStatisticsConditionView.CompanyID, _LoginUser); _IPositionStatisticsBarChartView.gvPositionStatisticsSource = UtilityPresenter.TurnToEmployeeSalaryStatisticsDataTable(employeeSalaryStatistics, UtilityPresenter.StatisticsTableTypeEnum. Position); } }
public frmAddUser(User user = null) { InitializeComponent(); userService = InstanceFactory.GetInstance <IUserService>(); this.user = user; }
public IdentityManager() { _userService = InstanceFactory.GetInstance <IUserService>(); }
public void Merge_from_PluginFamily_will_not_replace_an_existing_instance() { var factory = new InstanceFactory(typeof (IWidget)); ObjectInstance instance1 = new ObjectInstance(new AWidget()).WithName("New"); factory.AddInstance(instance1); var family = new PluginFamily(typeof (IWidget)); family.AddInstance(new ObjectInstance(new AWidget()).WithName("New")); factory.ImportFrom(family); Assert.AreSame(instance1, factory.FindInstance("New")); }
public void TestInstanceFactory() { TestObject obj = new TestObject(); IFactory<TestObject> factory = new InstanceFactory<TestObject>(obj); Assert.IsTrue(ReferenceEquals(obj, factory.Create())); Assert.IsTrue(ReferenceEquals(factory.Create(), factory.Create())); }