How do I store some object globally? - wpf

I'm new to WPF and used to ASP.NET. I have a WPF app that will require a login screen. Throught the rest of the app I want to be able to access a "Session" object that will contain some credentials information. How do I store that so that any view in my app can access that object?

You can also use lightweight container to store objects globally in loosely coupled way and retrieve these object using Dependency Injection pattern.
One of implementations of lightweight container is Unity Application Block from Microsoft (http://www.codeplex.com/unity) so you can start there and read more here and here.

The Application object has a Properties property that allows you to store and retrieve application wide objects.
It is better explained here:
How to: Get and Set Application-Scope Properties

There are a few ways to do this.
You can create a static class, perhaps you might call it "Session" which holds the data that you are interested in. Session might have a Dictionary that contains the data that you are interested in.
You can hold the data in the main form, and have the main form pass a data container to each view.
There might be better ways to do this that are more compatible with your design goals if you can provide more details about the implementation and use cases.

Related

DTOs and object graphs

I'm making an Angular2 SPA with a webAPI REST service that exposes an EntityFramework model.
The quickest way to get going is to load up a big object graph in a single controller action and pass out a big blob of JSON to the client, which can then split it up as it walks the object graph.
Is it considered better practice to build API actions for each object in the object graph and have the JS client pull the graph piecemeal as required?
The piecemeal approach requires many more controllers and actions and, correspondingly, angular services, i.e., more work! Do I need to just grasp the nettle and get on with it?
Actually it depends whether your are using Entity Framework in connected scenarios or in disconnected scenarios. Regarding your case, you are using Entity framework in disconnected scenarios, which mean that DBContext doesn't attach to object graph all the time, because you get the data from database, send it to the client and then close the context. For me, I would recommend to use divide your controllers and actions for each POCO or DTO because this will help you to maintain and attach each object individually rather than maintain the whole object graph at once. The problem will start to appear when you start editing or manipulating your entities because in disconnected scenarios you never know which object has been edited or deleted or added in a big object graph. However, you should maintain and manipulate each change in client side directly to the sever to reflect that update.
I don't know if this answers your question, but if you need any further explanation or code sample. please let me know.
I think you have to make one backend action for one angular2 page-level component. User shouldn't wait for extra data loads, only data that needed on this page.

Managing Big Data in Angular2

I'm following an Angular2 course having a background of Sencha ExtJS framework.
My question is pretty easy : with AngularJS how do you store and interact with big data structures? In all the course when a Service was retrieving data was always small and was stored in an array.
Why did I mention ExtJS? Because it offers classes called Store to, as the name says, store data and query it, with possibility of filtering,sorting,mapping and so on.
Let's make an example :
I have the list of the airports in the world and I want to offer it in a select. Of course i will setup the service injected to the select that offers the entire list. But then:
-I want to filter it as the user go on typing
-The array containing the data is an array of objects with other properties after the name like the country or the id
Which is the approach to follow?
As per my comments, here's my answer.
In Angular 2 we have smart components, which hosts logic and data, and dumb components which are pure views, with no logic and preferably stateless.
Ideally, you could retrieve your data from the API and deliver it to your smart components either returning the whole data or exposing a stream with RxJS.
An example using RxJS would be:
A service calling the APIs and returning an Observable with the data
A smart component consuming the service's data, in the form of a Subscription
One or more dumb component in showing the data which is pushed down by the smart component (acting as a container)
At this point, your data manipulation could reside either in the service or in the smart component (it depends on what you need to transform and how).
To manipulate the data, I suggest you use RxJS which offers the possibility to chain streams and filter, aggregate, map, ... methods. It is asynchronous.
If you can go for something less complex but blocking (it depends on your requirements), I'd suggest you use Lodash, which brings methods for collections to chain, map, filter, and aggregate data.

Change Spring configuraton on runtime

I need to use two different properties in Spring application-context.xml file depending on the database that is used in the application.
Are there any way to change a property in the Spring context depending on java.sql.DatabaseMetaData before the context is initialized?
Thank you very much!:)
It's possible to refresh your context once you load data and change the configuration regarding the values from database.
See http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/ConfigurableApplicationContext.html#refresh--
In that case it helped to inherit from Spring configuration class, and override methods in which I need to change a parameter. Thus, change in parameters occurs in runtime.
Refreshing context doesn't fit my needs as I need to load context in the correct way the first time.

Accessing an Object from other Method

I am trying to access view objects from Java method.
These objects are not viewed in my page. so I cant use getter and setter methods.
Is there a way I can retrieve data from these view objects using SQL queries?
Accessing view objects from the view layer is not a good practice.How ever if the required view object which you need to access is added to application module then you can access that from the model layer
methods(VOImpl and VORowImpl) pertaining to the view object used in the jsf page.
Just access the app module first and then get the required ViewObject and you can perform the required query on that.

Per installation configuration for SalesForce Application

I want my SalesForce Application to behave differently depending on a value that's set per environment. The value can be one of two values at present and will result in a different page being loaded and a different object instance being updated by the page.
Where would be the best place to store this? A single instance of a custom object? Or is there a dedicated store for this? Ideally the value could be updated using the Api so that a we can updated it without having to get clients to do it.
Sounds to me like you want to use a Custom Setting — these are similar to objects but setup exactly for this kind of thing, and they can even be done in a hierarchy such that different settings are used for different users.
Help for custom settings is here (must be logged in) and reference docs are here.

Resources