Heading for alternative using for prism and di/ioc. mef is skilful framework for prism but not so fast. trying to use autofac for prism because our application infrastructure have to many presentation layer like a web, mobile, tablet(silverlight) and desktop(wpf). mef is not good idea for web(if there is no pluggin operation etc. requirements)
tried mef and autofac together. used aggregate catalog and exposed parts to autofac but it's a not complatetly solution. there is to many problems to be solved. using are together.(prism, prism.mefextensions, prism.autofacextensions and autofac's mefintegration)
using prism.autofacextensions for alternating mef but autofac is not ready to prism i think. tried some alternative projects but not ready. also autofac is not inject import attributed object automatically and not have a scanning tool for directory(export attribute scanner. it's must be coded.) and all prism extensibility must be declared. i think its not ready to use for prism.
is there a any alternative ready to use for prism framework? we must use ioc container for all presentation layers. whats best solution?
Based on my understanding, Unity container supports all the layers you mentioned of ASP.NET Web API, Windows Phone 8, Silverlight and WPF.
In addition, Bootstrapper implementation and any other feature related to PRISM becomes relatively simple to achieve as PRISM already includes the UnityBootstrapper class which implement most of the required functionality.
You can find helpful information for Unity container in the following CodePlex Unity site:
Microsoft Unity Container 3
I hope this helps.
Related
I'm a little confused as to what integrated options I have for DI. I see it's pretty straightforward for .net core (for my particular projects), but I don't need to build a cross platform app and don't see the advantage to using core. However, it doesn't look like .net framework applications are still setup with Global.asax and without Startup.cs so does that mean there is no integrated DI option for .net framework 4.7? Do I still need to get a 3rd party solution or is there a way to use the same DI workflow in a .net framework project as is used in a core project?
Dependency Injection is not integrated by default in classic asp.net, you need to add a nuget package to handle DI (only integrated by default in asp.net core).
EDIT: Even though I found out how to do it as explained below, I still ended up going with Autofac because I didn't realize the Microsoft's solution only supports constructor injection, but not property injection.
I found instructions on how to do it here. I know link answers are bad, but I don't have time to do any more than this. If someone else wants to make an answer with full instructions I will mark it.
https://scottdorman.blog/2016/03/17/integrating-asp-net-core-dependency-injection-in-mvc-4/
Also note that if you are not using Owin already, it is not required. You can set it up just the same in Application_Start method of Global.asax. Only change you would need to make is when it references the Startup class in a statement that reflectively gets all the Controller classes, you will need to change that to be the class the code is in (or any other class in your assembly).
I am converting a .NET 2.0 Winforms applications to ASP.NET MVC3. The Winforms solution uses several projects for business logic, and the MVC application includes these projects. The projects are also used by a variety of Windows console applications.
The problem is that these projects use System.Windows.Forms.Application.StartupPath to find files they use, whereas for web development System.Web.HttpRunTime.AppDomainAppPath is used.
I would prefer that both solutions use the same projects and that these projects are modified as little as possible as they are large, old, and relatively undocumented. What is the correct way to address this issue?
Right now I am thinking that I would create a new configuration with each project that would define WEB, and then use #if/#else statements to include the correct depedency and to define the return of the getPath() method.
Before you start plaguing your code with preprocessors, you should consider creating an interface IApplicationConfigurator or IApplicationStarter
public interface IApplicationStarter
{
string GetPath();
}
And inject it with a MvcApplicationStarter or a WinformsApplicationStarter depending on your application. You can then have your project libraries have a dependency on the IApplicationStarter interface. It should require minimal implementation on the projects, and you can reuse the pattern for other common dependencies. Look into dependency injection frameworks as it takes this approach into the next level.
This is what class libraries are for. Create a class library project, move all the common bits there, and then have a separate WinForms and MVC project that both reference your class library.
Does anyone have a complete and working DI sample for WCF?
Every sample I find just gets me more confused. Does anyone know of a complete and working standalone simple sample that works with the built in stuff?
Maybe once I get a handle of the built in stuff, I can move on to different DI frameworks such as StructureMap or Unity with WCF.
My MVC project is currently using Unity for all its DI.
I recommend this one. I have already used it and it is fully working.
The code download for my book Dependency Injection in .NET contains a full, working example.
However, most of what you'll need to know is explained in this answer: Injecting data to a WCF service
This one is the most straightforward one I've found.
DI with Castle Windsor
Official Site http://docs.castleproject.org/Windsor.WCF-Integration-Facility.ashx
Blog article http://ayende.com/blog/2548/wcf-windsor-integration
Blog article with sample http://mikehadlow.blogspot.com/2008/11/windsor-wcf-integration.html
There is a fully working downloadable sample here on Codeplex. It uses the Unity.WCF NuGet package, so it's really the kind of slam dunk example you are looking for.
I am trying to create a pluggable ASP.NET MVC framework. I have extensively used Prism (CAB for silverlight) and am a huge fan and wish to implement the following items in my pluggable ASP.NET MVC framework
The framework will have a host to load the unity container and other infrastructure items like logging services and all.
Plugins will be independent MVC2 application. Every application will have IModule interface implemented which will initialize and register Controllers/VIEWS(Is this possible!!!) type in Unity?
This IModule will also register custom routes per plugin and add it to host Routes collection.
When the application will start, the plugins list will be loaded from the database/external file and IModule of the project will be called which will load the above mentioned items in Unity Container.
Whenever any request is made, the controller will be loaded from unity and the Views will be loaded (Is it possible that I register a custom view engine in unity which will point to physical path rather than embedding the resource in the dll)
Is this possible. The question may sound a bit stupid... :)
This is generally possible, though a lot of work from scratch. Fortunately Microsoft's Orchard project already does pretty much everything you are asking, and you can download the MVC source code to see how it's done. See: http://orchard.codeplex.com/
In Using StructureMap 2.5 to scan all assemblies in a folder, we can see that StructureMap uses AssembliesFromPath() to explicitly look for types to resolve. What is the equivalent of this in Microsoft Unity? Because Unity is such a generic term, searching for documents about this online is not that easy.
Update: Unity has something called an Assembly Matching Rule but its description does not communicate to me that it scans folders.
The Assembly Matching Rule is used for applying interception to classes constructed by Unity and not for container registration. Unity itself does not have any convention-based scanning functionality like StructureMap. There is a CodePlex project that adds similar functionality to Unity though. http://autoregistration.codeplex.com/
Registration by Convention was added in Unity 3.0. Nice examples of this feature are provided in "Developer's Guide to Dependency Injection Using Unity" in solution in samples named OtherUnitySamples. You can find the book here:
http://msdn.microsoft.com/en-us/library/dn178463(v=pandp.30).aspx
and code samples here:
unity.codeplex.com/downloads/get/683531