Browser history 3–trying to Nuget
This is the part 3 of 5 of my implementing of a MVC Browser history
MVC browser history – idea
Browser history –2 – implementing, small bugs
Browser history 3–trying to Nuget – modifications in order to can be transformed from an application to a component
Browser history 4–NuGet again – finally Nuget deployment
Browser history–part 5–conclusions – conclusions
TL;DR : Trying to add a feature (NuGET ) will conduce you to other features – apparently easy to implement – but took 2 hours…
Content:
First, source control is more important – http://www.joelonsoftware.com/articles/fog0000000043.html .I choose github – deploy is a breeze with GitHub for windows . More, appharbor integration with github is awesome – you can see the application live at http://browserhistory.apphb.com/ .
Now , for generating Nuget package, I should be moving the classes on their own assembly / dll. Also , added this blog to the info. Ensure it works the same. Uploaded to GitHub
And appharbor just deployed
Now, it will be good if I let user switch implementation between memory saving and database saving… in order to developers( that have installed the dll with NuGet ) switch easily to their database.
Created
BrowserUserHistoryRepositorySqlServer
and , after some implementing of IBrowserUserHistoryRepository , the method
public IBrowserUserHistoryRepository FilterByUser(string UserName)
put some problems – but solved with a private variable.
Now must decide the best way to switch between MemoryRepository and SqlServerRepository in
public static T AddOrRetrieveFromApplication<T>(HttpApplicationStateBase app)
where T:new()
First, we must retrieve at runtime the instance of the interface – so structuremap to the rescure.
Second, if we need to retrieve a class – must have at least a default constructor.
So the constraint of the T was gone away – and the code is
T result;
if (typeof(T).IsInterface) {
result =(T) ObjectFactory.GetInstance(type) ;
}
else
{
result = (T)Activator.CreateInstance(type);
}
Also, in global.asax the following lines were added:
//ObjectFactory.Configure(ce => ce.For<IBrowserUserHistoryRepository>().Use<BrowserUserHistoryRepositoryMemory>()); //uncomment those for sql server ce ObjectFactory.Configure(ce => ce.For<IBrowserUserHistoryRepository>().Use<BrowserUserHistoryRepositorySqlServer>());
Now, when deploy , AppHarbor will NOT found EntityFramework dll.
Added HintPath to csproj to find EF
<HintPath>..\packages\EntityFramework.5.0.0\lib\net40\EntityFramework.dll</HintPath>
as seen at
http://blog.appharbor.com/2012/04/24/automatic-migrations-with-entity-framework-4-3
and it works!
More, it works with sql server AppHarbor addon and transformation of web.config.
It took 2 hours to do this thing, apparently simple.
Now you can find the code source on github at https://github.com/ignatandrei/MVCbrowserHistory
You can browse the application at http://browserhistory.apphb.com/
Next time: (maybe some tests and ) NuGET!
Leave a Reply