Spring.NET & Immediacy CMS

Is there a way to embed dependencies in an Immediacy CMS control using Spring.NET, ideally without having to use a ContextRegistrycontrol to initialize it?

+3
source share
2 answers

I am going to answer this question with a solution that I have been using for more than a year with Immediacy 6.x. Theoretically, this should work with Alterian CMC 7.x (the successor to Immediacy) with some modification.

The problem here is that Immediacy already has a handler defined in web.config that deals with all aspx pages. However, I have found that this can be replaced by the entry for Spring.NET PageHandlerFactoryin web.config, as in most web applications!

However, some settings are still needed, as out of the box there are still problems with the preview. The process of obtaining Spring.NET for enjoyable playback using Immediacy Control:

  • Add regular entries to web.config for Spring.NET as indicated in the documentation . In this case, I have my object definitions in Spring.config.

  • Create the following abstract base class that will handle all Injection Dependency work:

    SpringImmediacyControl.cs

    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 page preview handler
    
            if (DefaultApplicationContext == null)
            {
                DefaultApplicationContext = ContextRegistry.GetContext() as WebApplicationContext;
                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);
        }
    }
    

    Spring.NET. OnInit , HTTP- Immediacy. , Spring .NET.

  • , Spring.NET Inversion of Control, reclvant Spring.config, :

    SampleControl.cs

    public class SampleControl : SpringImmediacyControl, INamingContainer
    {
        public string Text
        {
            get;
            set;
        }
    
        protected string InjectedText
        {
            get;
            set;
        }
    
        public SampleControl()
            : base()
        {
            Text = "Hello world";
        }
    
        protected override void RenderContents(HtmlTextWriter output)
        {
            output.Write(string.Format("{0} {1}", Text, InjectedText));
        }
    }
    

    Spring.config

    <objects xmlns="http://www.springframework.net">
        <object type="MyProject.SampleControl, MyAssembly" abstract="true">
            <property name="InjectedText" value="from Spring.NET" />
        </object>
    </objects>
    
  • , , "Hello world from Spring.NET!". .

, , .

, , Spring.NET, ButtonPluginConfig, , HTTP- Immediacy , Spring.NET. , ButtonPluginConfig gist.

0

Immediacy, .

- .net, . , Page .

Immediacy ect, , .net.

, , - , , - , , .

, , , , .

, , ...

WebClient wc = new WebClient();
this.Controls.Add(Page.ParseControl( wc.DownloadString("/childapp/yourcustomthing.aspx") ));

- ashx , .

, , , , querystrings, "", .

, , , - / .

+1

Source: https://habr.com/ru/post/1727235/


All Articles