I'm trying to get my first internship, and one of the skills required is ASP.Net. They said I needed to bring some code in, so I went though Microsoft's MVC3 tutorial (http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/intro-to-aspnet-mvc-3)
I changed it around the app around a bit to suit their specifications, which they were fine with.
Now they've asked me to design an interface which will provide IOC. I'm completely new to the topic, and am wondering if anyone knows some good beginner's guides or tips on IOC with MVC. I'm probably going to use ninject.
If you're familiar with the 'movie list' app from the tutorial, they would like me to design an interface which will ensure that the MoviesController will have no awareness of the database.
I know that's pretty vague, but that's pretty much all the instructions they gave me. Anyone have some advice for a IOC newb?
Thanks!
You'll find it useful to read Scott Allen's article on abstracting away the dbContext to an interface, then read the MVC3 section of the ninject wiki to get your dependency resolution set up.
The basic idea is that you pass your controllers an object implementing a custom interface to the dbContext when you construct them, and thereafter you do all your data manipulation through that object/interface.
That way when you want to test your controllers, you can pass a dummy object that returns whatever data you need without having to create a database full of test data.
Related
I am creating an ASP.Net MVC 5 website with EF Code First. Although I have written a lot of code and have worked in this business for a long time, I have no experience in deploying a managed website. It seems to me that the goal of EF Code First approach is to create a DB that just works and it's no good for real world deployment.
If that's the case, I was wondering if there is a conference talk, tutorial or other type of resource that I can use to learn about best practices for this purpose. Especially learning how to create a secure and sophisticated database from the scheme of my existing one.
I've searched around and read a lot of opinions about this and got a little confused. Since I'm using MVC 5, I think there are some old and some new ways to do this so I'm asking your advice to pick the best method that works for me.
I'm using Caliburn micro with a WinRT application and it looks like that there's no StorageManager class, anyone has suggestions about how to persist application/ViewModels state in this case.
TIA
This is not related to Caliburn.Micro but rather a general issue. You can either use Serialization but then you will have to pay attention to versioning and changes in your view model or you could save the fields you are interested in to a file using the normal IO methods or even store your view models in the database if you wish (although i think this might be a bit extreme).
Edit: Caliburn.Micro isn't a business application framework and there have been no library that tried to integrate business functionality with CM as far as i know, so this leaves you with serialization as your best option but as i said ser/des comes with some nightmares you have to manage such as version changes, class changes, etc.
There's another project called Catel which is a business application framework that contains an MVVM framework, anyway Catel uses a nice object called DataObjectBase ( actually now it is called ModelBase) which solves all problems of serialization and there is an article for that on code project if you want to read it and see how they have done it.
If you wish you can use the Catel.Core module which is a library with a lot of features for data handling (it contains the ModelBase class) or you can take a look at the source code and see how they have solved the issue with ser/des and implement that with Caliburn.Micro in your project.
What are the required steps to use SimpleMembership (ASP.NET MVC 4) with RavenDB (or other databases) instead of SQL Server?
I am used to override the MembershipProvider but how does it work with the new SimpleMembership?
I saw there is a SimpleMembershipProvider so I think I should override it, but I don't know if the methods are for storing data purpose only or if they should contain business/validation logic)...
What about configuration? I know the InitializeDatabaseConnection method is normally responsible for initializing the whole shebang, but I don't think I should call it if I don't use Entity Framework.
Unfortunately, I did not find a lot of resources about the new SimpleMembership except two links which have not been very useful:
http://igambin.blogspot.ca/2012/08/simplemembershipprovider-huh.html
http://blog.osbornm.com/archive/2010/07/21/using-simplemembership-with-asp.net-webpages.aspx
So here is what I found after looking at some of the the source code (MVC4).
http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/553690ac9488#src%2fWebMatrix.WebData%2fExtendedMembershipProvider.cs
SimpleMembership is an implementation of the abstract class ExtendedMembershipProvider.
The code inside SimpleMembership is mostly SQL operations and some calls to the underlying (called "previous" in the documentation) MembershipProvider.
I don't think it is of any use (in my case) to override SimpleMembership as its implementation is mostly tied to SQL Server. Instead, for what I understand, I should implement ExtendedMembershipProvider. Then, by setting this implementation in the web.config file, the WebSecurity helper would bypass SimpleMembership (default implementation) and call my implementation of the ExtendedMembershipProvider.
I don't think I will do this any soon since it looks even more complicated than before (more methods to implement)... but still doable.
However, all this said, I'm a bit disappointed that we still have to work with the MembershipProvider which, IMHO, is far (a lot of static and internal stuff) from the whole dependency injection thing that we love so much with ASP.Net MVC/WebApi.
Edit 1
This question was aked before Jon Galloway wrote this tutorial :
http://weblogs.asp.net/jgalloway/archive/2012/08/29/simplemembership-membership-providers-universal-providers-and-the-new-asp-net-4-5-web-forms-and-asp-net-mvc-4-templates.aspx
But my answer stays valid as this (taken from Jon Galloway article) resumes it:
Note that SimpleMembership still requires some flavor of SQL Server -
it won't work with MySQL, NoSQL databases, etc. You can take a look at
the code in WebMatrix.WebData.dll using a tool like ILSpy if you'd
like to see why - there are places where SQL Server specific SQL
statements are being executed, especially when creating and
initializing tables. It seems like you might be able to work with
another database if you created the tables separately, but I haven't
tried it and it's not supported at this point.
Here's my implementation for mongodb. Maybe it can help
https://github.com/malibeg/MongodbSimpleMembershipProvider#readme
SimpleMembership is not really meant to be used with the old MembershipProviders as it doesn't fullfill all of the same contracts that are assumed of normal MembershipProviders. Its mostly designed for use via the WebSecurity helper.
This link might be helpful for more info: Web Pages Tutorial
There is the requirement, to write a portal like ASP.NET based web application.
There should be a lightweigted central application, which implements the primary navigation and the authentication. The design is achieved by masterpages.
Then there are several more or less independent applications(old and new ones!!), which should easily and independent be integrated into this central application (which should be the entry point of these applications).
Which ways, architectures, patterns, techniques and possibilities can help and support to achieve these aims? For example makes it sense to run the (sub)applications in an iframe?
Are there (lightweighted and easy to learn) portal frameworks, which can be used (not big things like "DOTNETNUKE")?
Many thanks in advance for you hints, tips and help!
DON'T REINVENT THE WHEEL! The thing about DotNetNuke is that it can be as big or as small as you make it. If you use it properly, you will find that you can limit it to what you need. Don't put yourself through the same pain that others have already put themselves through. Unless of course you are only interested in learning from your pain.
I'm not saying that DNN is the right one for you. It may not be, but do spend the time to investigate a number of open source portals before you decide to write your own one. The features that you describe will take 1000s of hours to develop and test if you write them all from scratch.
#Michael Shimmins makes some good suggests about what to use to implement a portal app with some of the newer technology and best practice patterns. I would say, yes these are very good recommendations, but I would encourage you to either find someone who has already done it this way or start a new open source project on codeplex and get other to help you.
Daniel Dyson makes a fine point, but if you really want to implement it your self (there may be a reason), I would consider the following components:
MVC 2.0
Inversion of Control/Dependency Injection (StructureMap for instance)
Managed Extensibility Framework
NHibernate (either directly or through a library such as Sh#rp or Spring.NET
A service bus (NServiceBus for instance).
This combination gives you flexible user interface through MVC, which can be easily be added to via plugins (exposed and consumed via MEF), a standard data access library (NHibernate) which can be easily configured by the individual plugins to connect to specific databases, an ability to publish events and 'pick them up' by components composed at runtime (NServiceBus).
Using IoC and DI you can pass around interfaces which are resolved at runtime based on your required configuration. MEF gives you the flexibility of defining 'what' each plugin can do, and then leave it up to the plugins to do so, whilst your central application controls cross cutting concerns such as authentication, logging etc.
I'm very new to Cairngorm, so apologies for what's probably a simple question:
I'm working with a number of WCF services imported into Flex Builder 3 (via Data > Manage Web Services), and I'm wondering how to expose those services to the ServiceLocator in Cairngorm. From what I've read so far, it looks like Cairngorm prefers the services be defined in Services.mxml (or somehow in MXML), but that won't work in my case.
I'm working on an app right now where Services.mxml is driving me nuts... calls are just not being made. I've read the blog posts that describe solutions to this issue but it's a recurring, nagging problem so I want to find a more reliable approach. I believe that you could simply replace the code in your Delegate where you retrieve the reference to the web service
this.service = ServiceLocator.getInstance().getWebService("web service name here");
to something like this:
this.service = generated.webservices.MyService();
I'm hoping that, after that, the rest should be straight forward. I'm planning to do some testing tonight so I'll let you know how it goes.