By using Microsoft's Unity, I am able to override a dependency in the exact moment that I'm resolving an instance, for example:
var valueObjectThatOverridesAnyConfiguration = new object();
var container = new UnityContainer();
container.Resolve<ATypeWithConstructorArguments>(new DependencyOverride(typeof(object), valueObjectThatOverridesAnyPreviousConfiguration);
That will override any previous configuration on my UnityContainer and inject the instance I provided on the DependencyOverride.
Is there a way to specify it in a Container level ? Like an extension or something ? I don't want to do it at the resolve moment!
Thanks! Let me know if I'm being confuse to you, I'll provide more info.
Do you mean something like this. The part that sounds like your problem starts in the middle of the thread.
It allows you to do this
var container = new UnityContainer();
container.AddNewExtension<SemanticGroupExtension>();
container.RegisterGroup<IVehicle, Car>("Car").Use<IWheel, CarWheel>().Use<IEngine, CarEngine>();
container.RegisterGroup<IVehicle, Motorcycle>("Motorcycle").Use<IWheel, MotorcycleWheel>().Use<IEngine, MotorcycleEngine>();
var car = container.Resolve<IVehicle>("Car");
Assert.IsInstanceOfType(car.Wheel, typeof(CarWheel));
Assert.IsInstanceOfType(car.Engine, typeof(CarEngine));
var motorcycle = container.Resolve<IVehicle>("Motorcycle");
Assert.IsInstanceOfType(motorcycle.Wheel, typeof(MotorcycleWheel));
Assert.IsInstanceOfType(motorcycle.Engine, typeof(MotorcycleEngine));
The sources can be found here inside the TecX.Unity project.
Related
In the example code for the widgets in AMI.js they get the WidgetsHandle from 'base/widgets/widgets.handle'. Is there a way to access the widgets when just using the AMI library without access to the whole repo? I've tried doing
var wh = new AMI.WidgetsHandle(a,b,c,d)
But it says it's not a constructor.
(The example is https://github.com/FNNDSC/ami/blob/dev/examples/widget_handle/widget_handle.js)
You should use "AMI.HandleWidget" instead.
It is been exported there.
You code should look like:
const handle = new AMI.HandleWidget(...)
HTH,
I started working with CodedUI few months before to automate a desktop Application(WPF).
Just checking out for the best ways to create a framework for my Application.
As, I have seen in other automation tools, I feel the heart of an automation framework using any tool(UI Based) is the way it's object Repository is created i.e. how well the UI objects are defined. A Cleaner and well defined Object Repository always proves to be very helpful when it comes to updating your tests.
I am trying to discover the best way to store my UIObjects so that in case of any UI changes in my Application, I have to put minimum effort to update my automation test.
Also, If an Object changes in application, updating it only at one place should solve the problem.
This can be any kind of change like :
->change in just a property(This I feel would be very easy to update in automation Test. The best and Easiet way I feel is to simply update the .uitest file(the xml file) if possible.)
->change in hierarchy and position
->entirely new object added
For the 2nd and 3rd changes, updating scripts become a difficult job, esp if the UIObject is being referred at may places, in many TestMethods, or Modules.
Also, I have generally seen that in Test Methods, Variable Declarations are done to create a reference to the UIMap objects and those variables are further used in the TestMethod Code.
So, in this case If the UI of my application changes, I will have to update the variable decalaration in each of the Test Methods. I want to reduce this effort to changing the variable decalaration only at one place. OfCourse, I cannot have all the code inside only one Test Method. One way that came to my mind is as:
Can't I have simply one common place for all these Variable decalarations. We can give a unique and understandable name to each UIObject e.g.: The decalratoions will look like:
UITabPage UITabPage = this.UIMap.UISimWindow.UISelectEquipmentTabList.UITabPage;
WpfRow UIRow = this.UIMap.UISimWindow.UISelectEquipmentTabList.UITabPage.UIEquipmentDetailsTable.UIRow;
WpfText UIEquipmentTagText = this.UIMap.UISimWindow.UISelectEquipmentTabList.UITabPage.UIEquipmentDetailsTable.UIRow.UITagCell.UIEquipmentTagText;
WpfCheckBox UIEquipmentCheckBox = this.UIMap.UISimWindow.UISelectEquipmentTabList.UITabPage.UIEquipmentDetailsTable.UIRow.UICheckBoxCell.UICheckBox;
....
....
and use these variables wherever required. Hence, In case of any chnages also, there will be only one place where you will need to update thse objects.
But for this, These varaibles must be made STATIC. What can be problem with making these Object Variables static?
Please provide your suggestion on this topic. May be what I am thinking is not possible or practical. I just want to choose the best way to start with before I go too far with the automation scripts and realize later that my approach wasn't a good one.
Thanks in Advance,
Shruti
Look into using descriptive programming instead of using the UIMaps.
Make a static class with generic functions to assist. Going to give you some examples of how to set it up.
For example:
public WinWindow parentwin(string ParentControlName)
{
var parentwin = new WinWindow();
parentwin.SearchProperties.Add("Control Name", ParentControlName);
return parentwin;
}
public WinWindow childwin(string ChildWinControlName, string ParentControlName)
{
var childwin = new WinWindow(parentwin(ParentControlName));
childwin.SearchProperties.Add("Control Name", ChildWinControlName);
return childwin;
}
public WinButton button(string ButtonName,string ChildWinControlName, string ParentControlName)
{
var childwin = childwin(ChildWinControlName,ParentControlName);
var button = new WinButton(childwin);
button.SearchProperties.Add("Name", ButtonName);
}
public void ClickButton(string ButtonName,string ChildWinControlName, string ParentControlName)
{
var button = button(ButtonName,ChildWinControlName,ParentControlName);
Mouse.Click(button);
}
public void ChangeFocus(WinWindow NewFocus)
{
var NewFocus = new NewFocus();
NewFocus.SetFocus();
}
public void ChangeFocus(WinWindow NewFocusChild, string c)
{
var a = new NewFocus();
a.SetFocus();
}
ChangeFocus(childwin("WelcomeForm", "MainForm");
ClickButton("&OK", "WelcomeForm", "MainForm");
I have a node toplevel myapp variable that contains some key application state - loggers, db handlers and some other data. The modules downstream in directory hierarchy need access to these data. How can I set up a key/value system in node to do that?
A highly upticked and accepted answer in Express: How to pass app-instance to routes from a different file? suggests using, in a lower level module
//in routes/index.js
var app = require("../app");
But this injects a hard-coded knowledge of the directory structure and file names which should be a bigger no-no jimho. Is there some other method, like something native in JavaScript? Nor do I relish the idea of declaring variables without var.
What is the node way of making a value available to objects created in lower scopes? (I am very much new to node and all-things-node aren't yet obvious to me)
Thanks a lot.
Since using node global (docs here) seems to be the solution that OP used, thought I'd add it as an official answer to collect my valuable points.
I strongly suggest that you namespace your variables, so something like
global.myApp.logger = { info here }
global.myApp.db = {
url: 'mongodb://localhost:27017/test',
connectOptions : {}
}
If you are in app.js and just want to allow access to it
global.myApp = this;
As always, use globals with care...
This is not really related to node but rather general software architecture decisions.
When you have a client and a server module/packages/classes (call them whichever way you like) one way is to define routines on the server module that takes as arguments whichever state data your client keeps on the 'global' scope, completes its tasks and reports back to the client with results.
This way, it is perfectly decoupled and you have a strict control of what data goes where.
Hope this helps :)
One way to do this is in an anonymous function - i.e. instead of returning an object with module.exports, return a function that returns an appropriate value.
So, let's say we want to pass var1 down to our two modules, ./module1.js and ./module2.js. This is how the module code would look:
module.exports = function(var1) {
return {
doSomething: function() { return var1; }
};
}
Then, we can call it like so:
var downstream = require('./module1')('This is var1');
Giving you exactly what you want.
I just created an empty module and installed it under node_modules as appglobals.js
// index.js
module.exports = {};
// package.json too is barebones
{ "name": "appGlobals" }
And then strut it around as without fearing refactoring in future:
var g = require("appglobals");
g.foo = "bar";
I wish it came built in as setter/getter, but the flexibility has to be admired.
(Now I only need to figure out how to package it for production)
How can I hide a method for a related model?
Let's say that, in the demo app loopback-example-datagraph, I don't want to expose the DELETE /customers/{id}/orders method.
How should I go about this?
For loopback 1.x, the relation is mapped to a prototype method internally. To not expose it as REST APIs, try the following:
var customer = app.models.Customer;
customer.prototype.__delete_orders.shared = false;
Disclaimer I Have Never Used StrongLoop
Wild stab but it looks like this might work. When you add a relation it adds a method to the underlying model class. when you add a has many it adds this method
customer.orders.destroyAll(function(err) {
...
});
source: http://docs.strongloop.com/display/DOC/Creating+model+relations#Creatingmodelrelations-Methodsaddedtothemodel.1
You should be able to say something like
var customer = app.models.Customer;
customer.orders.destroyAll.shared = false;
Let's say I have this code:
Person = {};
var person = new Person();
Where Person is a class I defined in the file Person.js. Before invoking the code that executes above, I want to check to see if the Person class exists and if not I want to include it using require('./'+className). Doing this all dynamically, I only have a string to start with:
var className = 'Person';
How do I use my className string to identify if Person exists in Node JS? I know in the browser I can do this:
if(window[className])
Ah, I figured it out. In Node you can do:
var className = 'Person';
if(global[className])
It's impossible with Node.js to access the variables declared with var, and, as it is impossible to get a variable from a string in Javascript, you can not do what you want.
However, there should be another way to do what you want, if it is really a necessity, maybe you can use some dirty tricks like the one described here (it may not work given your project architecture):
Get all defined variables in scope in node.js