factory

angular load local json file via services

荒凉一梦 提交于 2019-12-21 02:45:12
问题 I am trying to load a local json file within the same directory as my service file. No JS errors and under the Net tab, I can see that the json file loaded. Yet setting the response txt to the var "static_obj" doesn't load JSON data. When I have the JSON data hard coded var WEBTEST = {} it loads just fine. Why? 'use strict'; webTestApp.factory('webtest', function ($q, $timeout) { var Webtest = { //Methods exposed for the class fetch: function(callback){ //fetch the data from below hard coded

Custom 'ExportFactory'

只愿长相守 提交于 2019-12-21 01:45:09
问题 A desktop application using MEF imports many 'ServiceProviders'. Each part (ServiceProvider) is a class inside a separate DLL. All DLLs are in 'Plugin" folder which is used by desktop application. Since I needed new Instances of my parts, ExportFactory was the best choice. The problem is my parts have constructors. I need pass some parameters into constructor of the part which is not supported by ExportFactory (MEF2, Preview2). I need something like this: // Each part has its own dependency

Factory method pattern in java using generics, how to?

こ雲淡風輕ζ 提交于 2019-12-20 14:43:22
问题 I have code that looks like follows: public interface BaseDAO{ // marker interface } public interface CustomerDAO extends BaseDAO{ public void createCustomer(); public void deleteCustomer(); public Customer getCustomer(int id); // etc } public abstract class DAOFactory { public BaseDAO getCustomerDAO(); public static DAOFactory getInstance(){ if(system.getProperty("allowtest").equals("yes")) { return new TestDAOFactory(); } else return new ProdDAOFactory(); } public class TestDAOFactory

Test AngularJS factory function with Jasmine

萝らか妹 提交于 2019-12-20 09:07:15
问题 I am very new to this (angularjs, jasmine, testacular) and I have this code (I simplified it a bit, leaving only what matters): //my_module.js angular.module('my_module', ['my_data']) .config([...]); .controller('my_controller', ['$scope', 'my_data', function($scope, my_data) { $scope.my_function = function() { return my_data.my_factory.save().then(function () { console.log('saved'); }, function() { console.log('Error'); }); } } ) //my_data.js angular.module('my_data', []) .factory('my

Test AngularJS factory function with Jasmine

天涯浪子 提交于 2019-12-20 09:05:23
问题 I am very new to this (angularjs, jasmine, testacular) and I have this code (I simplified it a bit, leaving only what matters): //my_module.js angular.module('my_module', ['my_data']) .config([...]); .controller('my_controller', ['$scope', 'my_data', function($scope, my_data) { $scope.my_function = function() { return my_data.my_factory.save().then(function () { console.log('saved'); }, function() { console.log('Error'); }); } } ) //my_data.js angular.module('my_data', []) .factory('my

“Singleton” factories, ok or bad?

时光怂恿深爱的人放手 提交于 2019-12-20 08:48:39
问题 I've a lot of (abstract) factories and they're usually implemented as singletons. Usually for the convenience of not having to pass them through layers who really have no business with using or knowing these factories. Most of the times I only need to make a decision at startup of which factory implementation the rest of the code program, maybe through some configuration it looks e.g. like abstract class ColumnCalculationFactory { private static ColumnCalculationFactory factory; public static

How to name factory like methods?

风流意气都作罢 提交于 2019-12-20 08:22:02
问题 I guess that most factory-like methods start with create . But why are they called "create"? Why not "make", "produce", "build", "generate" or something else? Is it only a matter of taste? A convention? Or is there a special meaning in "create"? createURI(...) makeURI(...) produceURI(...) buildURI(...) generateURI(...) Which one would you choose in general and why? 回答1: Some random thoughts: 'Create' fits the feature better than most other words. The next best word I can think of off the top

Ninject Conventions with Ninject Factory Extension To Bind Multiple Types To One Interface

霸气de小男生 提交于 2019-12-20 04:54:10
问题 I'm trying to expand on the scenario asked in the SO question titled Ninject Factory Extension Bind Multiple Concrete Types To One Interface by using Ninject Conventions for convention-based binding of the ICar implementations. I'm working off the accepted answer authored by Akim and his Gist outlining the full example. The difference is that I've replaced the explicit ICar bindings with convention-based bindings (or an attempt at it, at least ;) public class CarModule : NinjectModule {

Create a DbContext that handle a DatabaseFactory to use DapperExtensions more easily

纵饮孤独 提交于 2019-12-20 04:10:21
问题 This days I try to create an abstract base repository using some basic CRUD functions proposed by DapperExtensions. But the code given as an exemple use a SqlConnection which is made to connect to a SQL Server database. I want to be able to connect to all kind of Database (SQL Server, MySql, etc...). Also their code sample is repeated for each CRUD function as the code below show using (SqlConnection cn = new SqlConnection(_connectionString)) { cn.Open(); //Code doing something here... cn

The best way to implement Factory without if, switch

╄→尐↘猪︶ㄣ 提交于 2019-12-20 01:41:12
问题 I was looking through many approaches to implement a Factory pattern in Java and still couldn't find a perfect one which doesn't suffer from both if/switch plus doesn't use reflection. One of the best that I found was inside Tom Hawtin's answer here: https://stackoverflow.com/a/3434505/1390874 But my biggest concern is that it stores a HashMap of Anonymous classes in a memory. The question is what do people think about using Class.newInstance() in addition to Tom Hawtin's answer? This will