Lets say you have a source generator that produces an interface like this:
namespace Foo
{
public interface IBar
{}
}
Then you add this to a class with the [GenerateFactory] attribute applied to it like:
using Ninject;
using Foo;
[GenerateFactory]
public class ExampleClass
{
public ExampleClass(IBar bar)
{}
}
The generated class will look like this:
using System;
using Ninject;
using Ninject.Syntax;
using Ninject.Parameters;
public class ExampleClassFactory
{
public ExampleClass Create(IBar bar) // <--- Compiler error here because it's not fully qualified
{} // blahh
}
The reason this is the case is because Source Generators can not depend on each other. So when internally Auto Factories goes to resolve IBar it only knows it's type name as the ISymbol is null. We have two methods we could do to avoid this issue
Force all generated types to use the fully qualified name in the source class. Then define an analyzer that forces it.
Gather all the namespaces of classes that are being added to the factory and append them to the top. There is a chance of name space collisions however this does not require user interaction.
Lets say you have a source generator that produces an interface like this:
Then you add this to a class with the
[GenerateFactory]
attribute applied to it like:The generated class will look like this:
The reason this is the case is because Source Generators can not depend on each other. So when internally Auto Factories goes to resolve
IBar
it only knows it's type name as theISymbol
is null. We have two methods we could do to avoid this issue