Policy Injection and ASP.NET pages

Topics: Policy Injection Application Block
Apr 13, 2010 at 10:23 AM

Hi there,

I was wondering if there was a way to use policy injection in ASP.net pages, specially in control event handlers. ASP.Net engine creates page instances, so in order to do what I want there would have to be a way to instruct ASP.Net engine to create page instances using the policy injection factory create method instead of the new operator. Also it would be necessary to rewire controls and page event listeners so they'll point to the proxy created with the factory create method and not to some "pure" instance of the page class. Am I missing something and this is far less complicated than I've imagined? If not, is there a way to intercept Asp.Net engine in such a way?

Thanks a lot in advanced.

Amanda

Apr 13, 2010 at 10:48 AM
AmandaTarafaMas wrote:

Hi there,

I was wondering if there was a way to use policy injection in ASP.net pages, specially in control event handlers. ASP.Net engine creates page instances, so in order to do what I want there would have to be a way to instruct ASP.Net engine to create page instances using the policy injection factory create method instead of the new operator. Also it would be necessary to rewire controls and page event listeners so they'll point to the proxy created with the factory create method and not to some "pure" instance of the page class. Am I missing something and this is far less complicated than I've imagined? If not, is there a way to intercept Asp.Net engine in such a way?

Thanks a lot in advanced.

Amanda

 Hi there again,

I've been thinking and maybe I've got a solution.

public class MyOwnPage : System.Web.UI.Page, IMyOwnPage

{

[SomePolicyInjectionAttribute]

public void button_onClick(object sender, EventArgs args)

{

PolicyInjection.Wrap<IMyOwnPage>(this).button_onClick(sender, args);

}

public interface IMyOwnPage

{

void button_onClick(object sender, EventArgs args);

}

}

Of course, it would take an interface for every page class but I think this is a simple way to take advantage of policy injection in Asp.Net pages without bypassing or modifying Asp.Net engine. As a matter of fact I think this is a cute way to shield client code from the need to use the Policy Injection Factory to create or wrap objects, objects wrap themselves when there's need. I'm only worried with the posible overhead costs of wrapping the object each time. Is it to serious?

Anyway, if someone knows a solution that involves modifying or bypassing ASP.Net engine, I'd like to know.

Thanks a lot again.

Amanda

Apr 13, 2010 at 11:03 AM
AmandaTarafaMas wrote:
AmandaTarafaMas wrote:

Hi there,

I was wondering if there was a way to use policy injection in ASP.net pages, specially in control event handlers. ASP.Net engine creates page instances, so in order to do what I want there would have to be a way to instruct ASP.Net engine to create page instances using the policy injection factory create method instead of the new operator. Also it would be necessary to rewire controls and page event listeners so they'll point to the proxy created with the factory create method and not to some "pure" instance of the page class. Am I missing something and this is far less complicated than I've imagined? If not, is there a way to intercept Asp.Net engine in such a way?

Thanks a lot in advanced.

Amanda

 Hi there again,

I've been thinking and maybe I've got a solution.

public class MyOwnPage : System.Web.UI.Page, IMyOwnPage

{

[SomePolicyInjectionAttribute]

public void button_onClick(object sender, EventArgs args)

{

PolicyInjection.Wrap<IMyOwnPage>(this).button_onClick(sender, args);

}

public interface IMyOwnPage

{

void button_onClick(object sender, EventArgs args);

}

}

Of course, it would take an interface for every page class but I think this is a simple way to take advantage of policy injection in Asp.Net pages without bypassing or modifying Asp.Net engine. As a matter of fact I think this is a cute way to shield client code from the need to use the Policy Injection Factory to create or wrap objects, objects wrap themselves when there's need. I'm only worried with the posible overhead costs of wrapping the object each time. Is it to serious?

Anyway, if someone knows a solution that involves modifying or bypassing ASP.Net engine, I'd like to know.

Thanks a lot again.

Amanda

 Oops, some infinite recursiveness in the code up there. Well, put a flag or something to mark when the method executes first and that's it, i think.

Apr 13, 2010 at 12:47 PM
Edited Apr 13, 2010 at 12:49 PM

Wouldn't you consider using Unity?  Most of the PIAB stuff has already been moved there.  In addition, the Unity 1.2 Hands on Lab includes Integrating with ASP.NET.  ASP.NET still manages the  creation of pages but Unity can be used to apply injection and dependencies to the pages.  The Unity 1.2 HOL can be downloaded here: http://www.microsoft.com/downloads/details.aspx?FamilyID=93A5E18F-3211-44EF-B785-C59BCEC4CD6F&amp;displaylang=en&displaylang=en

 For Unity questions, you can post it here - http://unity.codeplex.com/Thread/List.aspx

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Apr 13, 2010 at 12:53 PM

Ok, thanks a lot. I haven't noticed Unity could be usefull here. I'll take a look. Thanks a lot.

Amanda