Tag: 注入

如何在Ruby中对数组中的对象的属性进行求和

我明白,为了总结Ruby中的数组元素,可以使用注入方法,即 array = [1,2,3,4,5]; puts array.inject(0, &:+) 但是,我如何总结对象数组中的对象的属性? 有一个对象数组,每个对象都有一个属性“现金”,例如。 所以我想把他们的现金余额合计为一个。 就像是… array.cash.inject(0, &:+) # (but this doesn't work) 我意识到我可以做一个新的数组只有财产现金和总结,但我正在寻找一个更干净的方法,如果可能的话!

使用TypeScript和$ inject机制定义AngularJS指令

最近我开始重新构build我正在使用TypeScript的Angular项目之一。 使用TypeScript类来定义控制器非常方便,并且由于static $inject Array<string>属性,所以可以很好地处理缩小的JavaScript文件。 而且你可以得到相当干净的代码,不需要从类定义中分解angular依赖关系: module app { 'use strict'; export class AppCtrl { static $inject: Array < string > = ['$scope']; constructor(private $scope) { … } } angular.module('myApp', []) .controller('AppCtrl', AppCtrl); } 现在我正在寻找解决scheme来处理指令定义的类似情况。 我发现一个很好的做法来定义指令作为函数: module directives { export function myDirective(toaster): ng.IDirective { return { restrict: 'A', require: ['ngModel'], templateUrl: 'myDirective.html', replace: true, link: (scope: […]

在Spring中将bean引用注入Quartz作业?

我设法在Spring中使用JobStoreTX持久存储来configuration和调度Quartz作业。 我不使用Spring的Quartz作业,因为我需要在运行时dynamic地调度它们,而且我发现将Spring和Quartz集成的所有示例都是在Springconfiguration文件中对shcedules进行硬编码的。无论如何,这里是我安排工作: JobDetail emailJob = JobBuilder.newJob(EMailJob.class) .withIdentity("someJobKey", "immediateEmailsGroup") .storeDurably() .build(); SimpleTrigger trigger = (SimpleTrigger) TriggerBuilder.newTrigger() .withIdentity("someTriggerKey", "immediateEmailsGroup") .startAt(fireTime) .build(); // pass initialization parameters into the job emailJob.getJobDataMap().put(NotificationConstants.MESSAGE_PARAMETERS_KEY, messageParameters); emailJob.getJobDataMap().put(NotificationConstants.RECIPIENT_KEY, recipient); if (!scheduler.checkExists(jobKey) && scheduler.getTrigger(triggerKey) != null) { // schedule the job to run Date scheduleTime1 = scheduler.scheduleJob(emailJob, trigger); } EMailJob是一个使用Spring的JavaMailSenderImpl类发送电子邮件的简单工作。 public class EMailJob implements Job […]

注入同样的东西,减less在ruby?

我看到他们在这里被logging在一起。 它们是一样的吗? 为什么Ruby有这么多的别名(比如map / collect的数组)? 非常感谢。

Spring框架中的@Inject和@Autowired有什么区别? 在什么情况下使用哪一个?

我正在浏览SpringSource上的一些博客,其中一位博客作者正在使用@Inject ,我想他也可以使用@Autowired 这是一段代码: @Inject private CustomerOrderService customerOrderService; 我不确定@Inject和@Autowired之间的区别,如果有人能解释在什么情况下使用哪个区别以及使用哪个区别,我将不胜感激。