FAQ Database Discussion Community


What's wrong with this factory dependencies issue?

javascript,angularjs,dependency-injection,factory
I'm working with AngularJS. I'd like to get a controller using a first factory which using another one. It could be schematize like that: MyCtrl -> Factory1 -> Factory2 So I tried to do in 3 different files (loaded in the following order): Factory2.js app.factory('Factory2', function () { ... })...

AngularJS redirect to view after data save

angularjs,redirect,controller,factory
After saving data from the employee-maintenance view, I am trying to redirect to the employee-details view. I want to do this within the controller's success method: $scope.insertEmployee = function (employee) { if (employee && $scope.IsNew) { employeeFactory.insertEmployee(employee) .success(function (data) { // after a successful save, redirect the user to the...

Are Angular.js services singletons or created each time?

angularjs,service,factory
I am confused about something regarding factories and services for Angular.js. In this question: angular.service vs angular.factory It says that services are created with the new keyword. While in this question: confused about service vs factory It says that services are "singletons". My questions are: When you add a 'service'...

Factory in Angularjs not working

angularjs,factory
I'm trying to use a factory in angularjs, but it's showing nothing on page, with no errors being displayed on console. Can anyone point out the mistake I am making? Here is plnkr link. var app = angular.module('myApp',[]); app.factory('customersFactory',function($scope){ var customers = [{ id:1, name: 'James', city: 'Seattle', orderTotal: 9.546,...

load json data into the factory file

json,angularjs,angularjs-directive,factory
I am new to angularJS and just started learning it. Can someone please help me with this example. How can I load the json file into the script.js file without directly adding the entire data. Here is the code of the program: enter code here Plunk...

Nice way of factory method pattern with inheritance

java,oop,design-patterns,factory,factory-pattern
Suppose I have following class hierarchy: class abstract Parent{} class FirstChild extends Parent {} class SecondChild extends Parent {} And I'd like to create DTO objects from each child: class abstract ParentDTO {} class FirstChildDTO extends ParentDTO{} class SecondChildDTO extends ParentDTO{} I think I need a factory method something like...

What is a good pattern for using multiple strategies one after another that is also extensible

c#,dependency-injection,unity,ioc-container,factory
I have a class that needs to get some data to perform analysis. Let's say the interface for getting the data is as follows: public interface IDataFetcher { List<someobject> GetData(); } In a very simple case my class will use this interface as follows in one of its methods: void...

Move some code from controller to factory in angular

angularjs,controller,factory
I must upload some file to server... I have some code in my controller, but the code is reusable.. So I would like to move it in a factory and then use the factory everytime I need it... I am not able to move this code to the factory.. If...

AngularJS - Not able to get value from factory service

angularjs,service,factory
I am very much new in AngularJS and due to which I am facing an issue and not able to understand the exact problem. The code which I tried is worked in normal javascript code but now I want to use custom service (factory function). Actually, I have a textarea...

PHP static factory method: dynamically instantiate instance of the calling class

php,static,runtime,subclass,factory
This PHP question is related to this question, but is a bit different. I have a static factory method called create() which instantiates a class instance. I want the method to dynamically instantiate an instance of the (sub)class on which it is called. So, the class it instantiates must be...

Store JSON data into a Variable

json,angularjs,factory
Hi Guys I am new to AngularJS started working on it just from 15 days I just want to load the JSON file data into a variable that is located in factory. Can anyone help me regarding this my code us here. myApp.factory('quizFactory', function () { var questions = [...

Go: factory returning pointer and interface{} type

interface,go,factory
Consider the following factory: Go playground type TypeA struct { placeholder int } func NewTypeA() *TypeA { return new(TypeA) } func main() { factory := make(map[string]func() interface{}) factory["TypeA"] = NewTypeA } This gives me the following error: cannot use NewTypeA (type func() *TypeA) as type func() interface {} in assignment...

Make a factory not Singleton in angularJS

javascript,angularjs,singleton,factory
UPDATE: Thanks for your reply! I've rewritten my code: (function () { 'use strict'; angular .module('Services', []).factory('services', ['$http', function($http,services) { function services($http) { var serviceProvider = function () { this.data = []; this.errors = []; } var model = { getInstance:function(){ return new serviceProvider(); } } serviceProvider.prototype.init = function(){//put some...

How should I use Angular services with factories for code reuse?

angularjs,factory,angular-services
I have some Angular Controllers where there's always the need to store an array of items, push elements to it and make it accessible. I thought then I could have a ServicesModule with a factory offering such service. So I got this service declaration: angular.module('ServicesModule',[]); angular.module('ServicesModule') .factory('newOrdersService', function($rootScope,$http) { var...

Angularjs .factory method return

angularjs,methods,return,factory
I have been able to get this .factory to work by adding a "return" in front of both the Restangular.all statement and the response. My question is why is it needed there? Why can't I just return the response? app.controller('MainController', ['GetIndexesFromES', '$scope', function(GetIndexesFromES, $scope) { $scope.indices = GetIndexesFromES.getUniqueIndexIDs(); console.log($scope.indices); }]);...

Factories and C#

c#,factory
I am writing a program that will have an interface similar to Windows Explorer. In this explorer view, there can be objects of various types, but each of the objects will implement the same interface so they can be treated the same way by the explorer and other parts of...

Angular JS: Async factory call issue

angularjs,asynchronous,angular-ui-router,factory
I'm new to angular and I'm creating a simple app. It navigates between projects, pulled in via JSON: http://plnkr.co/edit/FTfa1rcVaf85xTu65oSR?p=preview I am also using a factory, where I make a call such as get or getOne, so that it deals with the $http in one place, only calling it if the...

Using factory to expose a simple API

javascript,angularjs,factory
I'm trying to write a factory which exposes a simple users API. I'm new to AngularJS and I'm a bit confused about factories and how to use them. I've seen other topics but none that are a good match to my use case. For the sake of simplicity, the only...

AngularJS factory object is not automatically updating view through controller

angularjs,websocket,factory
So I have this issue that I have been scratching my head over for a few days now, it seems that I am either finding really outdated code, something is broken or I plainly have no clue what I am doing. I can't for the love of me get my...

angular $resource factory pass parameter

angularjs,factory,angular-resource
I have a factory that makes some $resource calls to the server. The setData function works fine. My question is how do I pass a parameter into the factory to be used in the SubmitAttendance function? I need to pass a id to be sent to the server .factory('AttendanceData', function...

when to use decorator and decorator factory?

python,python-2.7,factory,python-decorators
This gets bit of confusing with decorator takes no argument while decorator factory takes argument and still decorates a function It would be helpful when to use when description . Edit: Confusion is over an example: def before_run(func): print "hello from before run" def handle_arg(a,b): if(a>0): a= 100 return func(a,b)...

How to unit test a builder which uses a static singleton factory in its builder() method?

java,unit-testing,factory,builder
I am trying to unit test a Selenium page object API, and I have a bunch of builder classes that use a static singleton factory class to instantiate the desired object. I can't for the life of me figure out a way to unit test the build() method in the...

Factory which is not dependant on implementation

java,factory
I have an api which has some base implementations. I have a factory which gives the instances of that api to the clients. I want to change my factory to make it more generic so, if a new implementation of the api will be generated and its jar file will...

Angular - Use static json for translations before the user authorized and after - use data from server

angularjs,factory,community-translations
Is it possible to use static json for translations before the user authorized and after - use data from server?

Spring static factory with factory-method and parameter

spring,methods,parameters,static,factory
I have a problem transfering code to Spring applicationContext.xml The source is: File inFile = new File ("path/to/file/", "fileName.docx") WordprocessingMLPackage wordMLPackage = Docx4J.load(inFile); My not working solution is: <bean id="inFile" class="java.io.File"> <constructor-arg value="path/to/file/" /> <constructor-arg value="fileName.docx" /> </bean> <bean id="docx4j" class="org.docx4j.Docx4J" factory-method="load"> <constructor-arg ref="inFile" /> </bean> <bean...

How to define concrete factory beans inheriting from generic factory more elegant in Spring?

spring,generics,configuration,dependency-injection,factory
Stackoverflow community, I currently defined a generic factory like this: public class ResourceCrudServiceFactory<E, R extends ResourceSupport> implements FactoryBean<ResourceCrudService<R>> { private ObjectMapper mapper; private CrudService<E> entityCrudService; private BidirectionalResourceAssembler<E, R> assembler; @Override public ResourceCrudService<R> getObject() throws Exception { ResourceCrudServiceImpl<E, R> resourceCrudService = new ResourceCrudServiceImpl<E, R>();...

Avoid two passes over a list of validators

java,design-patterns,factory
I am validating the parameters passed to a series of commands in a file using the following code: for (Parameter p : s.getCommand(idx).getParameters()) { for (ValidationFactory.TYPES validationType : ValidationFactory.TYPES.values()) { validator = ValidationFactory.getValidator(validationType, errors); try { validator.validate(p); } catch (ValidationException e) { Report.logErrorMessage("Failed to validate: " + validationType); continue; }...

Push to an array from get:method

arrays,angularjs,push,factory
EDIT: Solved the question thanks to you. list() instead of list. Such a stupid question. Why pushing to array in a factory like this doesn't work? It works only if I make a push function inside the factory. var app = angular.module('app', []); app.factory('registeredUsersService', function() { var registeredUsers = [];...

Java: Classes do not find each other in package (factory design pattern)

java,design-patterns,design,factory
I have three different classes: Woman.java package human; public class Woman extends Human{ private final String pnr; private final String namn; public Woman(String n, String p){ namn = n; pnr = p; } public String toString(){ return "My name is "+namn+" and I am a woman."; } } Man.java package...

How do I get PicoContainer to start/stop/dispose a component injected by a factory?

java,dependency-injection,factory,picocontainer
I have a PicoContainer which caches all components. Since it caches all components, I expect it to call start, stop and dispose at the appropriate points in the container lifecycle. However, I'm finding that if I construct a component using a FactoryInjector, these methods don't get called at all, despite...

python class factory inherit random parent

python,python-2.7,inheritance,factory
I have some code like this: class Person(object): def drive(self, f, t): raise NotImplementedError class John(Person): def drive(self, f, t): print "John drove from %s to %s" % (f,t) class Kyle(Person): def drive(self, f, t): print "Kyle drove from %s to %s" % (f,t) class RandomPerson(Person): # instansiate either John...

MVC4 C# Project: Provide a single instance of an object across the application

c#,asp.net-mvc,razor,singleton,factory
Background I am going to provide the background here before posing my actual question: I am working on an ASP.NET MVC 4 project in C#. The current development task I am busy with is to implement RazorMachine (https://github.com/jlamfers/RazorMachine) in this web application in order to leverage the use of the...

Using FactoryMethod pattern

java,factory
I have two separate entities: public enum Rule implements Validatable, StringRepresentable{ //... } and public inteface Filter extends Validatable, StringRepresentable{ //... } Where public inteface Validatable{ public GenericValidator getValidator(); } and public interface StringRepresentable{ public String getStringRepresentation(); } GenericValidator is an abstract class having a number of subclasses I would...

use angular factory to hold a value for rest of application to access to minimize server calls

javascript,angularjs,promise,factory,angular-promise
I have the following factory: angularModule .factory('ArticleCategoryService', function ($http, $q) { // Service logic // ... var categories = []; var _getCategories = $http.get('/api/articles/category').success(function (_categories) { categories = _categories; }); // .error( function (data, status, headers, config) { // }); // Public API here return { getCategories: function () {...

Is there a simple way to combine Factories in Java?

java,factory
Suppose I have interfaces of factory classes FactoryA and FactoryB with methods for producing objects of type A and B respectively, and suppose I have implementations of these interfaces. Now suppose I need a factory class FactoryAB that implements both interfaces, i.e., produces both A and B. Is there a...

angularjs .then() doesn't work (then is not a function)

javascript,angularjs,service,factory
I have a little problem developing a simple GUI for a game idea using AngularJS (v1.3.15) and Angular-Route. Anyway, for the registration, i want to pre-check the availability for the username while being typed. I set up a $watch, call the factory service to get an $http.post answer, but in...

AngularJS reusable factory

javascript,angularjs,factory,abstract
I feel like this is probably a dumb question but I'm having trouble visualizing how to make this work. I have a factory used to share data between controllers, like this: app.factory('DataShare', function(){ //Share Data between controllers via the sharedItem object and the get/set functions var sharedItem = {}; function...

Run-time class instantiation based on external xml in Java

java,reflection,dependency-injection,xml-parsing,factory
I have an xml file that contains data I want to parse and read into my program so i can instantiate a class. The problem is, which class i want to instantiate wont be known until runtime. My xml will be a little like below. <dataitem class="FooClass"> <dataitem class="BarClass"> Classes...

TypeError: Factory.function is not a function

javascript,angularjs,factory,typeerror
I am writing my first angular application with a web api and I am having some problems with calling functions from a factory. I have two factories that looks like this: main.factory('Table', function ($http, $log) { return { build: function (token, cubeid) { return $http({ method: 'POST', url: 'http://localhost:50051/api/structure/cube', headers:...

Replacing a constructor call with a factory method call by using a proxy in C# [closed]

c#,factory,proxy-object
I might be going crazy, but I swear I've seen a snippet that allows the consumers of your code to write new Foo() while something like FooProxy.Create() is called behind the scenes instead of the constructor. I've been searching and searching for it, but now I cannot find it at...

Object creation patterns using Object.create()

javascript,inheritance,prototype,factory
I'm stuck on figuring out how to do multi-level inheritance while using Object.create() as opposed to traditional constructors. I've opened a fiddle here . We have two types of objects, programmers, and a "subclass" front-end developers. Programmers inherits from the programmer prototype object, and as you can see, all programmers...

AngularJS factory inside ng-class on body tag not working

angularjs,controller,factory,angular-services,ng-class
Was told to create service/factory and use it on global controller. It's my first time hearing global controller. Anyways, I created a factory called Scroll and injected it on our main.controller.js. The function in the factory is isScrollingEnabled which returns true or false. The other function is setScrolling which will...

Factory that takes constructors

c#,interface,factory
How can I make a factory that behaves like this: interface A { } class B: A { string b; public B(string b) { this.b = b; } } class Factory { public static T create<T>(/*somehow pass constructor parameters*/) where T: A { return new T(/*constructor parameters*/); } } B...

watch factory variable with Angular

javascript,angularjs,factory,watch
My single page application has 2 controllers : the first is for my main menu and the second is for the view. They share data with this factory myApp.factory('MenuFactory', function(){ var factory = { Monitor: "doneJob", Control: "", Report: "", Display: "", setMonitor: function(value){ factory.Monitor = value; }, setControl: function(value){...

C++ Factory Pattern With Templates

c++,templates,factory,factory-pattern
I'm trying to code an abstract factory using c++ templates. Due to the fact I've never done things like that before I'm encountering troubles. The code I wrote, as you can verify by yourself, is wrong and I have no idea on how to correct it. My idea is that...

Angular with Jasmine: mocking factory services

javascript,angularjs,unit-testing,jasmine,factory
I have the following controller defined in Angular JS that uses a service from Angular Material: angular.module('leopDirective', []) .controller('MenuCtrl', function ($scope, $timeout, $mdSidenav, $log) { $scope.mdSidenav = $mdSidenav; $scope.close = function () { $mdSidenav('left').close().then(function () { $log.debug("close LEFT is done"); $scope.closed = true; }); }; }); It depends on the...

Factory Object or Function, or Pass Unity Container?

c#,dependency-injection,unity,factory,factory-pattern
I have an object that provides a sequence value to various consumers. The provider must manage many sequences, because the consumers could ask to get a new value for any one of the ongoing sequences. All of the sequences follow the same pattern, but they are path dependent and thus...

Loading data from the factory in my controller

angularjs,controller,promise,factory
I am using the factory to do my API calls and I would like them to happen before the rest of my controller happens. Here is the code of the factory: define(['dashboard/module', 'lodash'], function (module) { 'use strict'; module.registerFactory('httpApiCallService', function ($http, $q) { var assetsInUse, assetsCoupled; var api = {...

What type of object should this function return?

c++,c++11,factory,smart-pointers,lifetime
Consider this class: class Widget { Widget::Widget(); bool initialize(); } A Widget has the following characteristics: initialize() must be invoked to fully construct initialize() may fail initialize() is expensive Given that, I am encapsulating creation in factory function that always returns the same Widget instance: Widget* widget() { static auto...

Java Factory pattern - How to prevent anonymous subclasses

java,factory,final
I'm doing a school assignment where I have to implement the Factory pattern. I have come a long way, but there is one last thing I have not been able to get working. I have the following classes: //Human.java package human; public abstract class Human{ public static Human create(String namn,...