I m going to explain the difference between BodyStyle = WebMessageBodyStyle.Bare and BodyStyle = WebMessageBodyStyle.Wrapped in WCF Rest Services.
Bare can only support one parameter that is not included in the TemplateUri but Wrapped can support multiple parameters and have some extra XML tags in the body.
I m going to show you an example:
Saturday, August 28, 2010
Saturday, August 21, 2010
How to load assembly and its references ignoring version number using Reflection
I want to load an assembly A.BC.dll that has a reference to A.XZ.dll and I dont care about the version number for A.BNM.dll, these two assemblies are located in a /ref folder.
Tuesday, August 17, 2010
Saturday, July 31, 2010
Translate<T> method in ObjectContext in Entity Framework 4
In Entity Framework 4, ObjectContext has a nice Translate<T> method. This method will materialize the result type. It takes your DbDataReader and materializes the data back into entities, the T can be a primitive type, an entity type, or any custom type you like, That type does not have to be defined in the Entity Framework conceptual model.
Thursday, July 29, 2010
How to install the latest Flex SDK into Flex builder 3
Installing the latest flex SDK into flex builder 3 is pretty simple. after you download the new version of SDK from Adobe website, then unzip that zip file and copy the content to a new folder created on a location
like C:\Program Files\Adobe\Flex Builder 3\sdks or any location you like, But I prefer that location.
From the main menu, select Window > Preferences > Flex > Installed SDKs and click Add to add a your new sdk and you can select the default SDK you want Flex builder to use to compile your program.
Cheers!
like C:\Program Files\Adobe\Flex Builder 3\sdks or any location you like, But I prefer that location.
From the main menu, select Window > Preferences > Flex > Installed SDKs and click Add to add a your new sdk and you can select the default SDK you want Flex builder to use to compile your program.
Cheers!
Wednesday, July 28, 2010
How to get only date part in T-sql DateTime
SELECT DATEADD(D, 0, DATEDIFF(D, 0, GETDATE())) OR SELECT CONVERT(DATETIME, FLOOR( CONVERT(FLOAT, GETDATE())))
Thursday, June 3, 2010
What is System.Lazy<T>
there is a new class in .Net framework 4.0 Called Lazy<T> that provides lazy initialization. Lazy initialization occurs the first time the Lazy<T>.Value property is accessed or the Lazy<T>.ToString method is called and the return value will be cached, it means the second time you access its value, the expression or function does not get executed.
Friday, April 23, 2010
URL with port number in Firefox
Firefox will block url containing port number for security reasons.
we can configure firefox to access url with port numbers.
we can override the blocked ports as follow:
Solution:
first type "about:config" into the address bar and press Enter.
then right click anywhere on the page and choose choose New -> String.
then type "network.security.ports.banned.override" in the textbox and click OK.
and in the value textbox we can enter port numbers seperated by comma., like 86,87,88
and then click OK.
we can configure firefox to access url with port numbers.
we can override the blocked ports as follow:
Solution:
first type "about:config" into the address bar and press Enter.
then right click anywhere on the page and choose choose New -> String.
then type "network.security.ports.banned.override" in the textbox and click OK.
and in the value textbox we can enter port numbers seperated by comma., like 86,87,88
and then click OK.
How to decouple your application from IoC container implementation
As we all know, DI(Dependency Injection) is a form of IoC(Inversion of Control). when I use IoC Containers like Unity or Autofac to implement dependency injection, my application will be dependent on that framework, so if i decide to go for another IoC Container, I need to change a lot of things.what I want to achieve is how to make this change easier and how to decouple my application from any specific container. what i did is creating an interface to work with.
I need to add a reference to Microsoft.Practices.ServiceLocation.dll
and I make use of IServiseLocator interface in that assembly.
Now, if you want to switch to another IoC Container, you only need to change one line and initialize another container.
cheers!
I need to add a reference to Microsoft.Practices.ServiceLocation.dll
and I make use of IServiseLocator interface in that assembly.
//IoCContainer.cs //----------------------------------------------------- using Microsoft.Practices.ServiceLocation; public abstract class IocContainer { public static IServiceLocator Locator; protected IocContainer() { Locator = CreateServiceLocator(); } protected abstract IServiceLocator CreateServiceLocator(); } public class IocContainerInitialization { private static IocContainer _iocContainer; public static void Initialize(IocContainer iocContainer) { _iocContainer = iocContainer; } public static IocContainer IocContainer { get { return _iocContainer; } } } //------------------------------------------------------------- //then for every IoC Container I want to use, I need to create a container //inheriting from that base IoCContainer class. //for example, for using Autofac //AutofacIocContainer.cs //---------------------------------------------------------- using Autofac.Integration.Web; using Autofac.Integration.Web.Mvc; using AutofacContrib.CommonServiceLocator; using Microsoft.Practices.ServiceLocation; public class AutofacIocContainer : IocContainer { protected override IServiceLocator CreateServiceLocator() { var containerBuilder = new ContainerBuilder(); //For MVC------------- containerBuilder.RegisterControllers(System.Reflection.Assembly.GetExecutingAssembly()); //------------------------------------------------ RegisterTypes(containerBuilder); ContainerProvider containerProvider = new ContainerProvider(containerBuilder.Build()); //For MVC------------------------------- System.Web.Mvc.ControllerBuilder.Current.SetControllerFactory(new AutofacControllerFactory(containerProvider)); //--------------------------------------------------- return new AutofacServiceLocator(containerProvider.ApplicationContainer); } private static void RegisterTypes(ContainerBuilder container) { //Cache per request container.Register(c => new DbHelper("MyConnectionString")).As().InstancePerLifetimeScope(); container.Register(c => new DbMapper(c.Resolve())).As(); container.Register(c => new TagRepository()).As(); container.Register(c => new UserRepository()).As(); } } //-------------------------------------------------------------- //Then, in your Global.asax file we need to initialize our Container. void Application_Start(object sender, EventArgs e) { IocContainerInitialization.Initialize(new AutofacIocContainer()); RegisterRoutes(RouteTable.Routes); }
Now, if you want to switch to another IoC Container, you only need to change one line and initialize another container.
cheers!
Subscribe to:
Posts (Atom)