Skip to content

Instantly share code, notes, and snippets.

@SimonRice
Created December 22, 2011 16:06
Show Gist options
  • Save SimonRice/1510815 to your computer and use it in GitHub Desktop.
Save SimonRice/1510815 to your computer and use it in GitHub Desktop.
Immediacy 6.x Control & Server-Side Button Plugin Configuration with Spring.NET support
using System;
using System.Web.UI;
using Immediacy.Web.UI.Design;
using Spring.Context;
using Spring.Context.Support;
using Spring.Web.Support;
namespace Immediacy.Spring
{
public abstract class SpringButtonPluginConfig : ButtonPluginConfig, ISupportsWebDependencyInjection
{
#region ISupportsWebDependencyInjection Members
public IApplicationContext DefaultApplicationContext
{
get;
set;
}
#endregion
protected override void OnInit(EventArgs e)
{
if (DefaultApplicationContext == null)
{
DefaultApplicationContext = WebApplicationContext.GetRootContext();
DefaultApplicationContext.ConfigureObject(this, this.GetType().FullName);
}
base.OnInit(e);
}
protected override void AddedControl(Control control, int index)
{
this.EnableViewState = false;
// handle DI for children ourselves -
// defaults to a call to InjectDependenciesRecursive
if (DefaultApplicationContext != null)
WebDependencyInjectionUtils.InjectDependenciesRecursive(DefaultApplicationContext, control);
base.AddedControl(control, index);
}
}
}
using System;
using System.Web.UI;
using Immediacy.Web.UI;
using Spring.Context;
using Spring.Context.Support;
using Spring.Web.Support;
namespace Immediacy.Spring
{
public abstract class SpringImmediacyControl : ImmediacyControl, ISupportsWebDependencyInjection
{
// You can do the same thing for other control classes, like LiteralControl
#region ISupportsWebDependencyInjection Members
public IApplicationContext DefaultApplicationContext
{
get;
set;
}
#endregion
protected override void OnInit(EventArgs e)
{
// Required for page preview, which is executed using Immediacy's page preview handler
if (DefaultApplicationContext == null)
{
DefaultApplicationContext = WebApplicationContext.GetRootContext();
DefaultApplicationContext.ConfigureObject(this, this.GetType().FullName);
}
base.OnInit(e);
}
protected override void AddedControl(Control control, int index)
{
this.EnableViewState = false;
// Handle DI for children ourselves - defaults to a call to InjectDependenciesRecursive
if (DefaultApplicationContext != null)
WebDependencyInjectionUtils.InjectDependenciesRecursive(DefaultApplicationContext, control);
base.AddedControl(control, index);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment