Any reason not to stick my CLLocationManager in a global variable? - xamarin.ios

Pretty much all viewcontrollers in the app I'm building needs a CLLocationManager. Is there any reason not to put it into a global variable (by way of a static class)? The alternative seems to be to set it up separately for every viewcontroller (wasteful) or pass it along to every viewcontroller (messy).

I usually setup a shared instance and call it...."LocationManager". You can check out an old revision here:
https://gist.github.com/1603316
Xamarin Mobile API is also another good project to get synced up with. The goal is to create a shared library that abstracts away the common interfaces to things like GPS, Accelerometer, Contacts, etc:
http://blog.xamarin.com/2011/11/22/introducing-the-xamarin-mobile-api/
Update: to answer your question the only reason I can think of to NOT to create a shared instance implementation is if you plan on accessing it from a bunch of different threads. To solve for this in my implementation I would simply create thread-safe members with thread-safe access patterns to those members.

Related

Dealing with DLLs in use case diagrams

I've developed a heterogeneous application which takes advantage of service oriented architecture. It consists of many components which are different in code and run in different platforms (example: an Android Client, a WP8 Client, a Web Server, a Desktop Client, a Website).
Now I'm trying to document that I have concluded to put each component in a separate subsystem. But I have come across the question of whether putting DLLs also in subsystems or not. This application consist of many DLL files and I can't really decide on this. I also have another question, since the main applications need to make use of class libraries like DLL, if I wanna show this relationship in the use case (all function in the main apps rely on the function in the DLL, and the functions in the DLL files cannot be executed separately), so is this "Include" or "Extend".
For example:
DLL A = Generates Machine ID
Desktop App uses the DLL A to register the Machine
So is this "Extend" or "Include" (I think include is right but wanna double check)
Depicting DLL-s in use case level is not something you do every day. I would forget about DLL and I would just simply write what those specific DLLs do (if somebody from "business" reads your documentation, he or she would not care about DLLs anyway, if this is a technical documentation, use Deployment or component diagram for this purpose).
From my understanding all DLLs do the same but runs on different platform, am I correct? If so, then just draw one use case and use include.
Why include, not extend? Extend is for eg. there is a use case which comprises other steps on specific condition whereas include means that specific use case is the same in different use cases.

How do I keep value objects from the server?

I communicate with the server through jsons, which both in Nodejs and in Actionscript are objects (serialized through string).
Those objects I use in my client, by reading / modifying them and also creating secondary objects (from Classes) relative to what came from the server.
I have one of two options to design my client and I am stuck at deciding which of them is more flexible/futureproof.
Keep data as it comes, create many methods to modify the objects, keep secondary objects somewhere separate.
Convert the data into instances of classes where each class has its own group of methods instead of piling the methods in the same place.
Usually I go with 2 because OOP is delicious but going with 1 seems much simpler in terms of quantity.
I guess my problem is that I can't figure out if my client is basically a View (from MVC) where the server is the Control (also from MVC), or if my client and server are two independent / separate projects that communicate, and I should consider the client as a MVC project in itself.
I would appreciate your 2 cents.
From your question it's not clear what 1. and 2. differ but looks like 1. is tightly coupled while 2. has better separation of concerns.
It depends on your application. Do you need to create client heavy app with rich UI/UX elements, or maybe a mobile app where bandwidth is limited? If the answer is yes, then go with a second approach (2.): build your MVC like structure or use existing MV* libraries, like Ember, Angular, Backbone, Knockout, etc.
If you need SEO support and don't have much of fron-end code, then rendering on the server-side is still an option. Even with this approach ORM like Mongoose can come in handy.
PS: JavaScript doesn't really have classes, because objects inherit from other objects. You can use prorotypal inheritance patterns for that.

ServiceStack Funq Container WeakReference proliferation

I recently wrote a small service that handles high amounts of throughput (on the order of 60+ million requests per day) and it is encountering memory issues. At first, I looked through all of the usual suspects convinced that it had to be something I wrote as opposed to something to do with the very useful very performance-oriented ServiceStack libraries. Upon using windbg to !dumpheap -stat on the production server, however, I discovered to my surprise that the vast majority of objects in memory were System.WeakReference types with !gcroots pointing to ServiceStack's Funq container.
I do not even use an IoC'ed data structure in my service, so I was wondering why this is happening? Am I initializing something incorrectly? My apphost initialize class just calls the base constructor with the assembly and name information, I do not override the Configure method at all.
public SvcName() : base("SvcName", typeof(SvcName).Assembly) { }
I read elsewhere that the System.WeakReference objects are often inserted by .NET in rare instances due to the Visual Studio compiling the binaries having the "Edit and Continue" debugging option on, but turning it off in my VS has no effect (presumably because the SS binaries are already compiled and just referenced in my project).
Has anyone else ever had this issue?
WeakReference is used in Funq to track IDisposable's that's stored in a WeakReference Stack of disposables as seen here. Basically Funq tracks every IDisposable WeakReference created so they can all be disposed of when the Container is disposed.
I would first look at whether you could reduce your use of IDisposable instances (e.g. using more singletons), otherwise try modifying the Funq source code to use Stack<IDisposable> instead of a Stack<WeakReference> and let me know if this resolves your issue, if it does I can include an opt-in option in ServiceStack to use Stack<IDisposable> instead of Stack<WeakReference>.

Help w/ DDD, SOA and PI

Without getting into all of the gory details, I am trying to design a service-based solution that will be consumed by several client applications. The solution allows admins to create and modify document templates which are used by regular users to perform data entry. It is my intent to make the application a learning tool for best practices, techniques, etc.
And, at the same time, I have to accomodate a schizophrenic environment because the 'powers that be' cannot ever stick to their decisions regarding technologies and tools. For example, I am using Linq-to-SQL today because they aren't ready to go to EF4 but there is also discussion about switching over to NHibernate. So, I have to make the code as persistent ignorant as possible to minimize the work required should we change OR/M tools.
At this point, I am also limited to using the partial class approach to extend the Linq-to-SQL classes so they implement interfaces defined in my business layer. I cannot go with POCOs because management insists that we leverage all built-in tooling, etc. so I must support the Linq-to-SQL designer.
That said, my service interface has a StartSession method that accepts a template identifier in its signature. The operation flows like this:
If a session already exists in the database for the current user and specified template, update the record to show the current activity. If not, create a new session object.
The session is associated with an instance of the template, call it the "form". So if the session is new, I need to retrieve the template information to create the new "form", associate it with the session then save the session to the database. On the other hand, if the session already existed, then I need to also load the "form" with the data entered by the user and stored in the session previously.
Finally, the session (with form definition and data) is returned to the caller.
My first objective is to create clean separation between the logical layers of my application. The second is to maintain persistence ignorance (as mentioned above). Third, I have to be able to test everything so all dependencies must be externalized for easy mocking. I am using Unity as an IoC tool to help in this area.
To accomplish this, I have defined my service class and data contracts as needed to support the service interface. The service class will have a dependency injected from the business layer that actually performs the work. And here's where it has gotten messy for me.
I've been try to go the Unit of Work and Repository route to help with persistance ignorance. I have an ITemplateRepository and an ISessionRepository which I can access from my IUnitOfWork implementation. The service class gets an instance of my SessionManager class (in my BLL) injected. The SessionManager receives the IUnitOfWork implementation through constructor injection and will delegate all persistence to the UoW but I find myself playing a shell game with the various logic.
Should all of the logic described above be in the SessionManager class or perhaps the UoW implementation? I want as little logic as possible in the repository implementations because changing the data access platform could result in unwanted changes to the application logic. Since my repository is working against an interface, how do I best go about creating the new session (keeping in mind that a valid session has a reference to the template, er, form being used)? Would it be better to still use POCOs even though I have to support the designer and use a tool like AutoMapper inside the repository implementation to handle translating the objects?
Ugh!
I know I am just stuck in analysis paralysis so a little nudge is probably all I need. What would be ideal would be if someone could provide an example how you would you would solve the problem given the business rules and architectural constraints I've defined.
If you don't use POCOs then your not really going to be data store agnostic. And using POCOs will allow you to get your system up and running with memory based repositories which is what you'll likely want to use for your unit tests anyhow.
The AutoMapper sounds nice but I wouldn't consider it a deal breaker. Mapping POCOs to EF4, LinqToSql, nHibernate isn't that time consuming unless you have hundreds of tables. When/If your POCOs begin to diverge from your persistence layer then you might find that an AutoMapper wont really fit the bill.

Lifetime management of a SimpleRepository

I'm just starting with SubSonic 3 and playing with the SimpleRepository approach. What's the intended lifetime of SimpleRepository classes when used in a desktop application?
Are you expected to keep creating a new instance for everytime you want to touch the database? Should I create an instance to use for each group of database calls that happen together? Should I create one singleton instance when the program starts and use it for everything?
I'm assuming it's one of the second two options, but it's not clear to me if it would be safe to create a single instance and use it for all calls or not. I'll be using an IoC container if that matters.
There's no harm in keeping the thing alive for the length of the desktop session (make sure you turn off the migration stuff). When I perf-tested the repo I kept one open the whole time and I didn't see any issues with memory leaks - but be sure to close off any readers if you execute them etc etc.

Resources