Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Pure.DI not recognizing attempts to register a type implementing a interface declared on a generated file #36

Unanswered
chrisbewz asked this question in Q&A
Discussion options

Hi,

I'm working on a library to communicate with a third party software using COM through some proxy classes I created like below code:

//SampleClass.cs
[ProxyGenerated<TComInterface>]
public sealed partial class SampleClass
{
}

Since this third party software has a considerable amount of interfaces to interact with,,I decided to implement a source generator to create the rest of proxy classes commom implementation. On the generator output some interfaces are added to compose the proxy class a well for example:

//SampleClass.g.cs
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("<source_generator_name>", "<source_generator_version>")]
public sealed partial class SampleClassProxy :
 IProxyBase<TComInterface>,
 global::System.ICloneable
{
 // Rest of implementation
}

The problem starts when i try to create a composition for example:

public partial class ProxyProvider
{
 [Conditional("DI")]
 private static void Setup() =>
 DI.Setup(nameof(ProxyProvider))
 .Bind<IProxyBase<TComInterface>>()
 .As(Lifetime.Singleton)
 .To<SampleClassProxy>();
 
}

Since my generator correctly added the necessary code I expect that SampleClassProxy implements IProxyBase, but some how the following error appears after trying to build:

  • [DIE003]: SampleClassProxy does not implement IProxyBase

Somehow if I pick the interface implementation previously at generated file and then move it to the original class file the project build without any issues. Is something that I'm missing to catch the expected result? This is my first try to use this library so I'm struggling a little with it.

You must be logged in to vote

Replies: 3 comments

Comment options

Hi!

Did I understand correctly that you created your own .NET source code generator that generates partial classes implementing additional interfaces? Then that's a curiosity :) Generators are executed sequentially one after another. Perhaps Pure.DI in this chain is earlier than your generator and the semantic model it uses to check bindings is built before the new syntax is added by your generator.

I have debugged the moment when the generators are enumerated when control is passed to them and I don't remember there being any sorting that could affect the sequence of code generation. If I can't find anything, I can suggest to add a "hint" (like this) for your case, which will disable the checks of bindings that relate to the implementation of interfaces.

You must be logged in to vote
0 replies
Comment options

@chrisbewz

Unfortunately I didn't find a way to control the code generation sequence so I added a "hint" named Hint.SeverityOfNotImplementedContract in version 2.0.48. You can use it as follows:

DI.Setup(...)
 .Hint(Hint.SeverityOfNotImplementedContract, "Hidden")

Please try this method and let me know if it worked for you.

You must be logged in to vote
0 replies
Comment options

By the way, the current discussion is also related to this one, there was a similar problem. But the situation there was more complicated, we needed information on a cosntructor that did not exist yet.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /