ByronMayne / AutoFactories

AutoFactories is a C# library used to generate factories for types to be used in dependency injection.
MIT License
1 stars 0 forks source link

Static constructors are not ignored for generation #21

Closed ByronMayne closed 4 months ago

ByronMayne commented 4 months ago

Description: Applying a GenerateFactory to a class with a static constructor leads wrong contracts being generated.

What Happens

The generated interface does not contain a member for the instance constructor. This following class

[GenerateFactory]
public class StaticConstructor
{
    static StaticConstructor()
    {}

    public StaticConstructor(string parameter)
    { }
}

Will generate this interface:

public interface IStaticConstructorFactory 
{
    /// <summary>
    /// Creates a new instance of <see cref="Ninject.Extension.AutoFactories.Sandbox.StaticConstructor"/>
    /// </summary>
    global::Ninject.Extension.AutoFactories.Sandbox.StaticConstructor Create();
}

and this implementation:

internal sealed partial class StaticConstructorFactory : global::Ninject.Extension.AutoFactories.Sandbox.IStaticConstructorFactory 
{
    private readonly global::Ninject.Syntax.IResolutionRoot m_resolutionRoot;
    public StaticConstructorFactory(global::Ninject.Syntax.IResolutionRoot resolutionRoot)
    {
        m_resolutionRoot = resolutionRoot;
    }
    /// <summary>
    /// Creates a new instance of <see cref="Ninject.Extension.AutoFactories.Sandbox.StaticConstructor"/>
    /// </summary>
    public global::Ninject.Extension.AutoFactories.Sandbox.StaticConstructor Create()
    {
        IParameter[] parameters = new IParameter[]
        {
        };
        global::Ninject.Extension.AutoFactories.Sandbox.StaticConstructor instance = m_resolutionRoot.Get<global::Ninject.Extension.AutoF
        return instance;
    }
    /// <summary>
    /// Creates a new instance of <see cref="Ninject.Extension.AutoFactories.Sandbox.StaticConstructor"/>
    /// </summary>
    public global::Ninject.Extension.AutoFactories.Sandbox.StaticConstructor Create(global::string parameter)
    {
        IParameter[] parameters = new IParameter[]
        {
            new ConstructorArgument("parameter", parameter)
        };
        global::Ninject.Extension.AutoFactories.Sandbox.StaticConstructor instance = m_resolutionRoot.Get<global::Ninject.Extension.AutoF
        return instance;
    }
}

What Should Happen

A single constructor is generated taking a single string parameter.