Monday, November 28, 2011

Thursday, November 17, 2011

Friday, November 11, 2011

Thursday, November 10, 2011

Unity 2 - InjectionMember usage

IUnityContainer RegisterType(Type t, params InjectionMember[] injectionMembers);
What "injectionMembers" parameters are for?

The overload with the InjectionMember array is used, when you do not provide a configuration file, that the Unity container tells how to create an instance of the given type or if you want to create an instance on another way than defined in the configuration file. The overloads are used, when you want to configure an unity container without an configuration file. An InjectionMember can be an constructor, property or method call. The following code, taken from the Unity help, shows how to use InjectionMembers through the fluent interface of the container.

IUnityContainer myContainer = new UnityContainer();
    new InjectionConstructor(12, "Hello Unity!"), 
    new InjectionProperty("MyStringProperty", "SomeText"));

<type type="MyObject" mapTo="MyObject" name="MyObject">
  <typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration"> 
      <param name="someInt" parameterType="int"> 
        <value value="12"/>
      <param name="someText" parameterType="string">
        <value value="Hello Unity!"/>
    <property name="MyStringProperty" propertyType="string">
      <value value="SomeText"/>
  typeConfig> type>
Another use case would be using InjectionFactory. For example:
var container = new UnityContainer();
container.RegisterType(new InjectionFactory((c) => Customer.NewCustomer()));
var newCustomer = container.Resolve();

I use InjectionFactory when there is no chance to add an injection attribute for a third party class constructor or property. In this case you can create delegate creating an object.

HTTP Error 500.19 - Internal Server Error

HTTP Error 500.19 - Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid.

Detailed Error Information
ModuleIIS Web Core
HandlerNot yet determined
Error Code0x800700b7
Config ErrorThere is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined
Config File\\?\C:\Temp\test2\web.config
Requested URLhttp://localhost:80/mvc2
Physical PathC:\Temp\test2
Logon MethodNot yet determined
Logon UserNot yet determined


If your plan is to deploy to an IIS that has an Application Pool running in .net 4.0 you will need to cleanup the web.config that includes all the section Definitions that point to .net 3.5. The reason this fails is because these section definitions are already included in the root web.config in .NET 4.0 (see %windir%\\framework\v4.0.30319\config\machine.config) that include all the system.web.extensions declared already.
Another quick fix is to have the application pool set to 2.0 just as your development machine appears to have. 
Delete or comment out all the system.web.extensions configuration section definitions and configuration section group definitions from the application-level

Powered by Blogger.