How can I use Simple Injector as a boostrapper in NancyFX? - nancy

I have seen the following two links
Nancy FX Discussion,
Simple Injector Discussion
However, I really want to use the simple injector.
Is there anyway I can use the simple injector as Bootstrapper in NancyFX(v.1.1)?

Related

$compile vs $componentController

I'm relatively new to Angular and have begun writing my application with a component architecture. When looking through the Angular docs it recommends testing components with the $componentController mock method.
However, when I look at how directives have traditionally been tested in Angular pre-1.5 it looks like the preferred method was to use the $compile service to actually build your directive template-and-all. By using $compile you can make assertions about your template logic as well as the controller logic. Whereas with the $componentController method you can only test the controller logic, which doesn't actually seem all that useful since most complexity is found in templates and services.
Can someone shed some light on modern best practices? To me it makes more sense to use $compile so that you can test the template as well. But why do the Angular docs not mention this at all and instead recommend $componentController?
One of the biggest problems with AngularJS is that it has $scope. This is the place you put your bindings onto that are used in the DOM. It introduced much confusion.
Every good application design should have layers: business logic, UI etc. In AngularJS those layers pretty much corresponded to controller for business logic and directives for UI. However, because of the $scope being available in directives, many people decided to not use controllers and put all business logic in directives. This led to hard-to-test directives because they simultaneously implemented both layers. Also test became slow since DOM manipulation is slow.
Ideally, you should put as much testing as possible into business logic and less in the UI. Since framework handles synchronization between business logic and UI there is little possibility of bugs there. But business logic is where most bugs are introduced. That's why in the newer AngularJS they recommend to use $componentController to test business logic in controllers, not directives.
New Angular doesn't have $compile and most tests are written for controllers, which are implemented as classes there.

Reference for common Typescript types in an Angular/Ionic app?

I'm working on my first Ionic (based on Angular 1.x) Typescript project. I'm finding that I'm spending way too much time looking around for the right type names to use for the various services, providers, etc.
I know that I can load up the actual .d.ts files themselves and inspect them (or, play around with Intellisense) to find the right types. However, it would be a whole lot easier to just glance at a cheat sheet/quick reference that looks something like the following:
Angular
$rootScope: angular.IRootScopeService
$scope: ng.IScope
$state: ng.ui.IStateProvider
$timeout: ng.ITimeoutService
Ionic
$ionicModal: ionic.modal.IonicModalService
$ionicLoading: ionic.loading.IonicLoadingService
$ionicPlatform: ionic.platform.IonicPlatformService
Cordova
etc.
Does such a reference exist? Or, could someone who is a bit more experienced than I throw together a quick guide? It would be immensely helpful for Typescript newcomers as the "language" becomes more mainstream.

Is there a way I can use angular-generator without yeoman?

Basically what I want is a scaffolding tool (without bower and other stuff that it comes with) and controller, service/factory generators.
Yeoman is great but I was wondering if there's anything minimalist cli out there for angular.
Well, if all you want is a base angular app structure, that is called a boilerplate. There are a few available:
https://github.com/angular/angular-seed
https://github.com/ngbp/ngbp
https://github.com/angular-app/angular-app
However, you seem to also want a controller, service/factory generator. This will always require:
some kind of task runner (like Grunt)
or an IDE that supports templates.
Since you don't seem to like grunt (grunt IS AWESOME), these IDEs might help you...
Eclipse supports template, you can find some here
IntelliJ's PHPStorm or WebStorm have a feature called Live Templates which, IMHO, are far better than eclipse. You can find some premade templates here, but is easy to roll your own, as explained in this tutorial.
If you want a command line interface but not Yeoman's, you might want to have a look at the "Generation" section of this collection. As of today, it has one option that uses Lineman and two that made their own CLI, but they use bower. Anyway, if what you're looking for exists, it should be in there somewhere.

Angular.js beginner: Is Yeoman scaffolding the wrong way to go?

I am trying to add Angular to my arsenal and just started playing around with it this weekend. Looks cool!
In one of the videos done by Google, the guy recommended Yeoman. I'm watching another tutorial video on it now as well: https://www.youtube.com/watch?v=rqdRXqeqgZs
However, it looks like it generates everything (even writes tests for you??). In the video above, to generate a route he ran yo angular:route myroute which generated the controller, route, view, and test. I mean it's great that I get to see the structure, but I wrote like 0 lines of code.
Perhaps I should just start off with something like this where the file structure is way simpler but at least I have to write more lines of code? https://github.com/davidb583/white-angularjs-app
For a beginner, which do you recommend for a first project?
For a beginner to AngularJS, don't check out Yeoman. It's a very useful tool remember, but before you use it, understand why it was built.
Start off with AngularJS's tutorial - it is one of the best tutorials out there. It tells you all that you need to know to explore off on your own. I started out with that and at the end of it, I just loved the entire framework.
I did not start off with Yeoman until building 2-3 applications using AngularJS. Once you do this, you figure out some common tasks that you carry out for every AngularJS application.
That's where Yeoman comes in. Rather than doing the same thing again and again for each application you use Yeoman to automate a lot of stuff. Once you know the why of using Yeoman, you will understand the how of using it.
Without having worked in AngularJS sufficiently, do not try to use Yeoman. You will enjoy the tool but then you will be left wondering how to work with AngularJS without it.
My 2 cents.
To smalls app, Yeoman is awesome. But you will know his limits when you will want to split your app into modules.
with yeoman, you will have a structure like that:
scripts/
controllers
controller1.js
controller2.js
...
directive/
...
But In large app you probably want to have:
scripts/
controllers
userModule
controller.js
myOtherModule
controller.js
...
directive/
...
And for that, you need to create manually all the files.
My advice is to always start with yeoman but use their route/directive/etc generator only at the begining of your project.
For the tests, it only generate a file and a very simple test, ofcourse you need to modify it, to cover your whole app.
In addition Yeoman provide you a lot of tools with grunt like minifications of your assets, a jshint to use the best coding practices, etc.

Best Approach to Test Backbone Views with Templates Using Jasmine

I am learning backbone so I am building a simple Backbone app. I am using jasmine framework to test my backbone app.
As luck would have it, my first jasmine test was for a Backbone View. This is a very simple view that uses a haml-js template. App users rails 3.1 so the whole thing is packaged via sprockets with the help of haml-sprockets gem, and it works.
However when I test with jasmine I get an error
TypeError: Cannot call method 'backbone/templates/admin_personal_attribute_template' of undefined
I understand this is because haml-js template is not present.
Normally this template is accessed like this:
$(this.el).html(window.JST["backbone/templates/admin_personal_attribute_template"]({pars:this.model.attributes}));
(i.e. haml-sprockets gem compiles is using haml-js and appends to window.JST).
I am looking for the 'best', i.e. least disruptive and, hopefully, simple, way to test my views + templates in jasmine.
I have found a number of ways to do it, but not sure as what is the 'best':
Use jasmine-headless-webkit . This will utulize sprockets, but loose ability to access jasmine server, so simple but some loss of flexibility
Using phantom.js as desribed by japhr (sorry stackoverflow prevented me from posting more links) will work around the server-side limitations, but this seems to be a very new and untested method, so flexible but not simple
Pre-generate your templates as desribed here. This is conceptually simple, but require some maintenance - so some coding work
Assuming I have a project with ~ 20 models and ~ 40 views and templates, what is the best way to go?
Check this article: Unit Testing Backbone Applications With Jasmine
It has some examples how to implement unit tests for Backbone JS view
Also there is an O'Reilly book "Developing Backbone.js Applications" which has a whole chapter on testing views with Jasmine and qUnit
I've written an in depth blog post on making Backbone.js, CoffeeScript and Jasmine play nicely together. Hopefully it will be useful for anyone who stumbles on this question: http://ihid.co.uk/blog/backbone-js-coffeescript-jasmine-haml-and-rails-working-together

Resources