/// <summary> /// Indicates that the service should be self-bound. /// </summary> /// <returns>The fluent syntax.</returns> public IBindingWhenInNamedWithOrOnSyntax <T1> ToSelf() { this.Binding.ProviderCallback = StandardProvider.GetCreationCallback(this.Binding.Service); this.Binding.Target = BindingTarget.Self; return(new BindingConfigurationBuilder <T1>(this.Binding.BindingConfiguration, this.ServiceNames, this.Kernel)); }
/// <summary> /// Indicates that the service should be bound to the specified implementation type. /// </summary> /// <typeparam name="T">The type of the returned syntax.</typeparam> /// <param name="implementation">The implementation type.</param> /// <returns>The fluent syntax.</returns> protected IBindingWhenInNamedWithOrOnSyntax <T> InternalTo <T>(Type implementation) { StandardProvider.AssignProviderCallback(this.BindingConfiguration, implementation); this.BindingConfiguration.Target = BindingTarget.Type; return(new BindingConfigurationBuilder <T>(this.BindingConfiguration, this.ServiceNames)); }
/// <summary> /// Indicates that the service should be self-bound. /// </summary> /// <returns>The fluent syntax.</returns> public IBindingWhenInNamedWithOrOnSyntax <T1> ToSelf() { StandardProvider.AssignProviderCallback(this.BindingConfiguration, this.Binding.Service); this.Binding.Target = BindingTarget.Self; return(new BindingConfigurationBuilder <T1>(this.Binding.BindingConfiguration, this.ServiceNames)); }
protected void GridView_CustomDataCallback(object sender, ASPxGridViewCustomDataCallbackEventArgs e) { string Standards = e.Parameters; long SumPrice = StandardProvider.SumPrice(Standards); e.Result = SumPrice; }
protected void GridView_InitNewRow(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e) { StandardVM CloneItem = new StandardVM(); if (bool.Parse(HttpContext.Current.Session["isCloneRow_Com"].ToString()) == true && GridView.FocusedRowIndex >= 0) { //List<int> selectedIds = GridView.GetSelectedFieldValues("Id").ConvertAll(id => (int)id); //CloneItem = StandardProvider.GetSingleById(selectedIds.Last()); CloneItem = Mapper.Map <StandardVM>(StandardProvider.GetSingleById(GridView.GetRowValues(GridView.FocusedRowIndex, "Id").ToString())); HttpContext.Current.Session["isCloneRow_Com"] = false; PropertyInfo myFieldInfo; foreach (var myProperty in typeof(StandardVM).GetProperties()) { myFieldInfo = typeof(StandardVM).GetProperty(myProperty.Name); if (myFieldInfo == null) { continue; } var ttt = myFieldInfo.GetValue(CloneItem); e.NewValues[myProperty.Name] = myFieldInfo.GetValue(CloneItem); } } }
/// <summary> /// Indicates that the service should be bound to the specified implementation type. /// </summary> /// <param name="implementation">The implementation type.</param> public IBindingWhenInNamedWithOrOnSyntax <T> To(Type implementation) { Binding.ProviderCallback = StandardProvider.GetCreationCallback(implementation); Binding.Target = BindingTarget.Type; return(this); }
/// <summary> /// Indicates that the service should be self-bound. /// </summary> public IBindingWhenInNamedWithOrOnSyntax <T> ToSelf() { Binding.ProviderCallback = StandardProvider.GetCreationCallback(Binding.Service); Binding.Target = BindingTarget.Self; return(this); }
public IEnumerable <IBinding> Resolve( Multimap <Type, IBinding> bindings, IRequest request) { var service = request.Service; if (!service.IsGenericType) { return(Enumerable.Empty <IBinding>()); } var type = service.GetGenericArguments()[0]; if (service.GetGenericTypeDefinition() != typeof(IOptions <>)) { return(Enumerable.Empty <IBinding>()); } var validatorType = typeof(OptionsManager <>).MakeGenericType(type); var binding = new Binding(service) { ProviderCallback = StandardProvider.GetCreationCallback(validatorType) }; return(new[] { binding }); }
/// <summary> /// Indicates that the service should be bound to the specified implementation type. /// </summary> /// <typeparam name="T">The type of the returned syntax.</typeparam> /// <param name="implementation">The implementation type.</param> /// <returns>The fluent syntax.</returns> protected IBindingWhenInNamedWithOrOnSyntax <T> InternalTo <T>(Type implementation) { this.BindingConfiguration.ProviderCallback = StandardProvider.GetCreationCallback(implementation); this.BindingConfiguration.Target = BindingTarget.Type; return(new BindingConfigurationBuilder <T>(this.BindingConfiguration, this.ServiceNames, this.Kernel)); }
/// <summary> /// Indicates that the service should be bound to the specified implementation type. /// </summary> /// <typeparam name="TImplementation">The implementation type.</typeparam> public IBindingWhenInNamedWithOrOnSyntax <T> To <TImplementation>() where TImplementation : T { Binding.ProviderCallback = StandardProvider.GetCreationCallback(typeof(TImplementation)); Binding.Target = BindingTarget.Type; return(this); }
public StandardProviderBenchmark() { var ninjectSettings = new NinjectSettings { // Disable to reduce memory pressure ActivationCacheDisabled = true, LoadExtensions = false }; var kernelConfigurationWithoutBindings = new KernelConfiguration(ninjectSettings); #region FromConstructorArguments _contextWithConstructorArguments = CreateContext(kernelConfigurationWithoutBindings, kernelConfigurationWithoutBindings.BuildReadOnlyKernel(), new List <IParameter> { new ConstructorArgument("location", "Biutiful"), new PropertyValue("warrior", "cutter"), new ConstructorArgument("warrior", new Monk()), new ConstructorArgument("weapon", new Dagger()), }, typeof(NinjaBarracks), ninjectSettings); _contextWithConstructorArguments.Plan = kernelConfigurationWithoutBindings.Components.Get <IPlanner>().GetPlan(typeof(NinjaBarracks)); #endregion FromConstructorArguments #region FromBindings var kernelConfigurationWithBindings = new KernelConfiguration(ninjectSettings); kernelConfigurationWithBindings.Bind <IWarrior>().To <Monk>().InSingletonScope(); kernelConfigurationWithBindings.Bind <IWeapon>().To <Dagger>().InSingletonScope(); _contextWithoutConstructorArguments = CreateContext(kernelConfigurationWithBindings, kernelConfigurationWithBindings.BuildReadOnlyKernel(), new List <IParameter>(), typeof(NinjaBarracks), ninjectSettings); _contextWithoutConstructorArguments.Plan = kernelConfigurationWithBindings.Components.Get <IPlanner>().GetPlan(typeof(NinjaBarracks)); #endregion FromBindings #region FromDefaultConstructor _contextWithDefaultConstructor = CreateContext(kernelConfigurationWithBindings, kernelConfigurationWithBindings.BuildReadOnlyKernel(), new List <IParameter>(), typeof(Dagger), ninjectSettings); _contextWithDefaultConstructor.Plan = kernelConfigurationWithBindings.Components.Get <IPlanner>().GetPlan(typeof(Dagger)); #endregion FromDefaultConstructor _warriorParameterTarget = CreateWarriorParameterTarget(); _standardProvider = new StandardProvider(typeof(StandardProviderBenchmark), kernelConfigurationWithoutBindings.Components.Get <IPlanner>(), kernelConfigurationWithoutBindings.Components.Get <IConstructorScorer>()); }
public void Constructor() { var type = typeof(Ninja); var actual = new StandardProvider(type, _plannerMock.Object, _constructorScorerMock.Object); Assert.Same(type, actual.Type); Assert.Same(_plannerMock.Object, actual.Planner); Assert.Same(_constructorScorerMock.Object, actual.ConstructorScorer); }
public IEnumerable <IBinding> Resolve(Multimap <Type, IBinding> bindings, IRequest request) { Type service = request.Service; if (typeof(IValidator).IsAssignableFrom(service)) { Type genericArgumentType = request.Service.GetGenericArguments()[0]; Type nullValidatorType = typeof(NullValidator <>).MakeGenericType(genericArgumentType); var binding = new Binding(service); binding.ProviderCallback = StandardProvider.GetCreationCallback(nullValidatorType); return(new[] { binding }); } return(Enumerable.Empty <IBinding>()); }
/// <summary> /// Indicates that the service should be bound to the speecified constructor. /// </summary> /// <param name="newExpression">The expression that specifies the constructor.</param> public IBindingWhenInNamedWithOrOnSyntax <T> ToConstructor(Expression <Func <IConstructorArgumentSyntax, T> > newExpression) { var ctorExpression = newExpression.Body as NewExpression; if (ctorExpression == null) { throw new ArgumentException("The expression must be a constructor call.", "newExpression"); } Binding.ProviderCallback = StandardProvider.GetCreationCallback(ctorExpression.Type, ctorExpression.Constructor); Binding.Target = BindingTarget.Type; this.AddConstructorArguments(ctorExpression, newExpression.Parameters[0]); return(this); }
/// <summary> /// Indicates that the service should be bound to the specified constructor. /// </summary> /// <typeparam name="TImplementation">The type of the implementation.</typeparam> /// <param name="newExpression">The expression that specifies the constructor.</param> /// <returns>The fluent syntax.</returns> protected IBindingWhenInNamedWithOrOnSyntax <TImplementation> InternalToConstructor <TImplementation>( Expression <Func <IConstructorArgumentSyntax, TImplementation> > newExpression) { var ctorExpression = newExpression.Body as NewExpression; if (ctorExpression == null) { throw new ArgumentException("The expression must be a constructor call.", "newExpression"); } this.BindingConfiguration.ProviderCallback = StandardProvider.GetCreationCallback(ctorExpression.Type, ctorExpression.Constructor); this.BindingConfiguration.Target = BindingTarget.Type; this.AddConstructorArguments(ctorExpression, newExpression.Parameters[0]); return(new BindingConfigurationBuilder <TImplementation>(this.BindingConfiguration, this.ServiceNames)); }
/// <summary> /// Returns any bindings from the specified collection that match the specified service. /// </summary> /// <param name="bindings">The multimap of all registered bindings.</param> /// <param name="request">The service in question.</param> /// <returns>The series of matching bindings.</returns> public IEnumerable <IBinding> Resolve(Multimap <Type, IBinding> bindings, IRequest request) { var service = request.Service; if (!TypeIsSelfBindable(service)) { return(Enumerable.Empty <IBinding>()); } return(new[] { new Binding(service) { ProviderCallback = StandardProvider.GetCreationCallback(service) } }); }
/*----------------------------------------------------------------------------------------*/ #region Protected Methods: Bindings /// <summary> /// Determines which binding should be used for the specified service in the specified context. /// </summary> /// <param name="service">The type whose binding is to be resolved.</param> /// <param name="context">The context in which the binding is being resolved.</param> /// <returns>The selected binding.</returns> protected virtual IBinding ResolveBinding(Type service, IContext context) { Ensure.NotDisposed(this); IBinding binding = Components.BindingSelector.SelectBinding(service, context); // If the requested service type is generic, try to resolve a binding for its generic type definition. if (binding == null && service.IsGenericType && !service.IsGenericTypeDefinition) { Type genericTypeDefinition = service.GetGenericTypeDefinition(); if (Logger.IsDebugEnabled) { Logger.Debug("Couldn't find binding for actual service type {0}, trying for generic type definition {1}", Format.Type(service), Format.Type(genericTypeDefinition)); } binding = Components.BindingSelector.SelectBinding(genericTypeDefinition, context); } // If there was no explicit binding defined, see if we can create an implicit self-binding. if (binding == null && Options.ImplicitSelfBinding && StandardProvider.CanSupportType(service)) { if (Logger.IsDebugEnabled) { Logger.Debug("No binding exists for service {0}, creating implicit self-binding", Format.Type(service)); } binding = CreateImplicitSelfBinding(service); AddBinding(binding); } if (Logger.IsDebugEnabled) { if (binding == null) { Logger.Debug("No binding exists for service {0}, and type is not self-bindable or generic", Format.Type(service)); } else { Logger.Debug("Selected {0} for service {1}", Format.Binding(binding), Format.Type(service)); } } return(binding); }
/// <summary> /// Returns any bindings from the specified collection that match the specified service. /// </summary> /// <param name="bindings">The dictionary of all registered bindings.</param> /// <param name="request">The service in question.</param> /// <returns>The series of matching bindings.</returns> public IEnumerable <IBinding> Resolve(IDictionary <Type, ICollection <IBinding> > bindings, IRequest request) { var service = request.Service; if (!this.TypeIsSelfBindable(service)) { return(Enumerable.Empty <IBinding>()); } return(new[] { new Binding(service) { ProviderCallback = StandardProvider.GetCreationCallback(service, this.planner, this.scorer), }, }); }
public IEnumerable <IBinding> Resolve(Multimap <Type, IBinding> bindings, IRequest request) { var service = request.Service; if (!service.IsInterface || !service.Name.StartsWith("I")) { return(Enumerable.Empty <IBinding>()); } return(new[] { new Binding(service) { ProviderCallback = StandardProvider.GetCreationCallback(GetDefaultImplementationType(service)) } }); }
public StandardProviderTests() { _ninjectSettings = new NinjectSettings { // Disable to reduce memory pressure ActivationCacheDisabled = true, LoadExtensions = false }; _requestMock = new Mock <IRequest>(MockBehavior.Strict); _contextMock = new Mock <IContext>(MockBehavior.Strict); _plannerMock = new Mock <IPlanner>(MockBehavior.Strict); _planMock = new Mock <IPlan>(MockBehavior.Strict); _bindingMock = new Mock <IBinding>(MockBehavior.Strict); _providerCallbackMock = new Mock <Func <IContext, IProvider> >(MockBehavior.Strict); _providerMock = new Mock <IProvider>(MockBehavior.Strict); _constructorScorerMock = new Mock <IConstructorScorer>(MockBehavior.Strict); _standardProvider = new StandardProvider(typeof(Monk), _plannerMock.Object, _constructorScorerMock.Object); }
/// <summary> /// Attempts to handle a missing binding for a service. /// </summary> /// <param name="service">The service.</param> /// <returns><c>True</c> if the missing binding can be handled; otherwise <c>false</c>.</returns> protected virtual bool HandleMissingBinding(Type service) { Ensure.ArgumentNotNull(service, "service"); if (!TypeIsSelfBindable(service)) { return(false); } var binding = new Binding(service) { ProviderCallback = StandardProvider.GetCreationCallback(service), IsImplicit = true }; AddBinding(binding); return(true); }
/// <summary> /// Returns any bindings from the specified collection that match the specified request. /// </summary> /// <param name="bindings">The multimap of all registered bindings.</param> /// <param name="request">The request in question.</param> /// <returns>The series of matching bindings.</returns> public IEnumerable <IBinding> Resolve(Multimap <Type, IBinding> bindings, IRequest request) { var service = request.Service; if (typeof(Controller).IsAssignableFrom(service)) { var binding = new Binding(service) { ProviderCallback = StandardProvider.GetCreationCallback(service) }; binding.Parameters.Add( typeof(AsyncController).IsAssignableFrom(service) ? new PropertyValue("ActionInvoker", ctx => ctx.Kernel.Get <NinjectAsyncActionInvoker>()) : new PropertyValue("ActionInvoker", ctx => ctx.Kernel.Get <NinjectActionInvoker>())); return(new[] { binding }); } return(Enumerable.Empty <IBinding>()); }
private void UpdateNavBarName() { List <bool> ActivedList = new List <bool>(); List <bool> BlockedList = new List <bool>(); for (int i = 0; i < GridView.VisibleRowCount; i++) { ActivedList.Add((bool)GridView.GetRowValues(i, "Actived")); BlockedList.Add((bool)GridView.GetRowValues(i, "Blocked")); } GridView.JSProperties["cpActived"] = ActivedList; GridView.JSProperties["cpBlocked"] = BlockedList; HttpContext.Current.Session["isActBloChanged_Com"] = false; GridView.JSProperties["cpAllCount"] = StandardProvider.Count(x => true); GridView.JSProperties["cpInActivedUnBlockedCount"] = StandardProvider.Count(x => x.Actived == false && x.Blocked == false); GridView.JSProperties["cpActivedBlockedCount"] = StandardProvider.Count(x => x.Actived == true && x.Blocked == true); GridView.JSProperties["cpInactivedBlockedCount"] = StandardProvider.Count(x => x.Actived == false && x.Blocked == true); GridView.JSProperties["cpActivedUnBlockedCount"] = StandardProvider.Count(x => x.Actived == true && x.Blocked == false); GridView.JSProperties["cpUpdatedByCount"] = StandardProvider.Count(x => x.CreatedBy == User.Identity.Name || x.UpdatedBy == User.Identity.Name); }
/// <summary> /// Indicates that the service should be bound to the specified constructor. /// </summary> /// <typeparam name="TImplementation">The type of the implementation.</typeparam> /// <param name="newExpression">The expression that specifies the constructor.</param> /// <returns>The fluent syntax.</returns> protected IBindingWhenInNamedWithOrOnSyntax <TImplementation> InternalToConstructor <TImplementation>( Expression <Func <IConstructorArgumentSyntax, TImplementation> > newExpression) { if (!(newExpression.Body is NewExpression ctorExpression)) { throw new ArgumentException("The expression must be a constructor call.", nameof(newExpression)); } this.BindingConfiguration.InitializeProviderCallback = (planner, scorer) => this.BindingConfiguration.ProviderCallback = StandardProvider.GetCreationCallback(ctorExpression.Type, planner, ctorExpression.Constructor); this.BindingConfiguration.Target = BindingTarget.Type; this.AddConstructorArguments(ctorExpression, newExpression.Parameters[0]); return(new BindingConfigurationBuilder <TImplementation>(this.BindingConfiguration, this.ServiceNames)); }
protected void GridView_CustomCallback(object sender, DevExpress.Web.ASPxGridViewCustomCallbackEventArgs e) { switch (e.Parameters) { case "CloneRow": HttpContext.Current.Session["isCloneRow_Com"] = true; GridView.JSProperties["cpMessage"] = string.Format("OrderDate {0} is later than {1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortDateString()); break; case "DetailRow": HttpContext.Current.Session["isDetailRow_Com"] = true; GridView.JSProperties["cpMessage"] = string.Format("OrderDate {0} is later than {1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortDateString()); break; case "Actived": if (GridView.FocusedRowIndex >= 0) { var itemID = GridView.GetRowValues(GridView.FocusedRowIndex, "Id").ToString(); StandardProvider.SetActived(itemID, true); GridView.DataBind(); UpdateNavBarName(); } GridView.JSProperties["cpMessage"] = string.Format("OrderDate {0} is later than {1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortDateString()); break; case "InActived": if (GridView.FocusedRowIndex >= 0) { var itemID = GridView.GetRowValues(GridView.FocusedRowIndex, "Id").ToString(); StandardProvider.SetActived(itemID, false); GridView.DataBind(); UpdateNavBarName(); } GridView.JSProperties["cpMessage"] = string.Format("OrderDate {0} is later than {1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortDateString()); break; case "Blocked": if (GridView.FocusedRowIndex >= 0) { var itemID = GridView.GetRowValues(GridView.FocusedRowIndex, "Id").ToString(); StandardProvider.SetBlocked(itemID, true, User.Identity.Name); GridView.DataBind(); UpdateNavBarName(); } GridView.JSProperties["cpMessage"] = string.Format("OrderDate {0} is later than {1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortDateString()); break; case "UnBlocked": if (GridView.FocusedRowIndex >= 0) { var itemID = GridView.GetRowValues(GridView.FocusedRowIndex, "Id").ToString(); StandardProvider.SetBlocked(itemID, false, User.Identity.Name); GridView.DataBind(); UpdateNavBarName(); } GridView.JSProperties["cpMessage"] = string.Format("OrderDate {0} is later than {1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortDateString()); break; case "InActivedBlocked": if (GridView.FocusedRowIndex >= 0) { var itemID = GridView.GetRowValues(GridView.FocusedRowIndex, "Id").ToString(); StandardProvider.SetActivedBlocked(itemID, false, true, User.Identity.Name); GridView.DataBind(); UpdateNavBarName(); } GridView.JSProperties["cpMessage"] = string.Format("OrderDate {0} is later than {1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortDateString()); break; case "ActivedUnBlocked": if (GridView.FocusedRowIndex >= 0) { var itemID = GridView.GetRowValues(GridView.FocusedRowIndex, "Id").ToString(); StandardProvider.SetActivedBlocked(itemID, true, false, User.Identity.Name); GridView.DataBind(); UpdateNavBarName(); } GridView.JSProperties["cpMessage"] = string.Format("OrderDate {0} is later than {1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortDateString()); break; case "Delete": if (GridView.FocusedRowIndex >= 0) { var itemID = GridView.GetRowValues(GridView.FocusedRowIndex, "Id").ToString(); StandardProvider.Delete(itemID); //StandardProvider.Delete(itemID); GridView.DataBind(); UpdateNavBarName(); } GridView.JSProperties["cpMessage"] = string.Format("OrderDate {0} is later than {1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortDateString()); break; //case "Delete": //List<int> selectedIds = GridView.GetSelectedFieldValues("Id").ConvertAll(id => (int)id); //foreach (var item in selectedIds) //{ // StandardProvider.DeleteSuit(item, false); // HttpContext.Current.Session["isActBloChanged_Com"] = true; //} //GridView.DataBind(); //GridView.JSProperties["cpMessage"] = string.Format("OrderDate {0} is later than {1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortDateString()); //break; } GridView.JSProperties["cpParameters"] = e.Parameters; }
/// <summary> /// Indicates that the service should be self-bound. /// </summary> /// <returns>The fluent syntax.</returns> public IBindingWhenInNamedWithOrOnSyntax <T1> ToSelf() { this.Binding.InitializeProviderCallback = (planner, scorer) => this.Binding.ProviderCallback = StandardProvider.GetCreationCallback(this.Binding.Service, planner, scorer); this.Binding.Target = BindingTarget.Self; return(new BindingConfigurationBuilder <T1>(this.Binding.BindingConfiguration, this.ServiceNames)); }