Skip to content

ymartel06/MagicIoc

Repository files navigation

MagicIoc

A C# IOC based on naming convention, nothing to configure!

You have just to fallow some rules, and the IOC will work.

How to do

  1. Your assembly where you have Interfaces and Implementations have to be named by only 2 words.

Example: MyCompany.Core -> It will result MyCompany.Core.dll

  1. Add an injection modules

Add a MagicModule class at the root of your assembly. The method must be named GetInjectionModules and the class MagicModule.

Example:

public class MagicModule
{
    /// <summary>
    /// Gets the injection modules.
    /// </summary>
    /// <returns></returns>
    public static List<InjectionModule> GetInjectionModules()
    {
        List<InjectionModule> registrations = new List<InjectionModule>();
        InjectionModule injectionModule = new InjectionModule
            {
                Service = typeof (IMyService),
                Implementation = typeof (MyService)
            };
        registrations.Add(injectionModule);
        return registrations;
    }
}
  1. That's all!

You can try it like that:

DependencyResolver.ServiceLocator.GetService<IMyService>().Test();

About

A C# IOC based on naming convention, nothing to configure!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages