I have a form:
public partial class mdiAuthenticationForm : Form
{
public Services.Authentication.IAuthentication Authenticator { get; set;
public Services.Authentication.IAuthorization Authorizor { get; set; }
and I want to inject concrete classes for the two attributes above.
I have a type for each of them, and am using the app.config for the configuration information. But, I don't want to create an interface for each page, just to inject, so, how can I inject into each page?
Basically, what to I put in the type attribute in the following type element, or, how can I do this?
<type type="" mapTo="mdiAuthenticationForm,project">
<typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration">
<property name="Authenticator" propertyType="Services.Authentication.IAuthentication,project">
<dependency name="mssqlauth" />
</property>
<property name="Authorizor" propertyType="Services.Authentication.IAuthorization,project">
<dependency name="mssqlautz" />
</property>
</typeConfig>
</type>
I am using the Unity Framework for this, btw.
Thank you.
Edit: I get the container and then I am trying to inject by using this:
Container.Configure<InjectedMembers>().ConfigureInjectionFor<mdiAuthenticationForm>();
Basically you want to use property injection to inject mdiAuthenticationForm's dependencies. Can't you do something like the following?
Add your type mappings in the config file:
Put Dependency attributes on Authentication and Authorization properties.
Then finally in your code, do the following to get an instance of mdiAuthenticationForm:
If you don't want to add mdiAuthentication in the config file, you can also do the following:
This should resolve the dependencies on an existing instance and wire them up.
I got it to work, not pretty, but it works. The last problem was that I have to include Form.ShowDialog in my interface.
First is the main part of my code that created and called the form, from Program.cs, then the second is my interface. I wanted this to be modal, which is why I use ShowDialog. I also moved the two attributes into a new controller, but I still have one property to set, to make certain it is working properly.