URL Through JavaScript

JavaScript by default gives you full access to the browser’s url property through the global window.location object.  Let’s use this following url as an example:

“http://www.demo.com/Sports/Running/Shoes?item=1&size=10&color=green”

To get the full url use:

first_full

To only get the origin use:

second

With these two properties you can extract any values that you want using regular string functions, such as:

If you don’t care about the origin use the following.

thrid

If you would like to remove the query string values as well use this

fourth

Onion Architecture

Recently I have been writing some applications using the Onion Architecture one of which is here: Github.  I guess I’ve been using this pattern for a long time, I just didn’t know the name for it until I read Jeffrey’s blog, which is a very good read.  One thing that you have to consider though is that, is it worth adding the complexity that this architecture enforces for your particular application.  And by complexity, I mean not the usual way of referencing each section (Presentation –> Business –> Data), which most of the developers will already be familiar with.  I wouldn’t recommend using this on a small scale application where the traditional layered architecture will suffice, I just don’t think the added complexity will payoff. However, once you get the hang of how the different sections are separated and wired together at runtime, it is really not that bad.

Making the Core layer completely independent and only having to deal with interfaces promotes loose coupling and makes it a highly testable system, which I really like. Also putting the infrastructural concerns on the outside and not making it the main layer that all other layers depends on makes complete sense.  If you think about it, the Core application layer shouldn’t care or have any inclination about where the data comes from, whether it is cached or not, how the logging is done, etc,.  It should only concern itself with the domain/business logic that it has to deal with and nothing more.