47 lines
763 B
Plaintext
47 lines
763 B
Plaintext
include::../why-dotnet.adoc[]
|
|
|
|
== How to fix it
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,csharp,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
[Export(typeof(IFooBar))]
|
|
[PartCreationPolicy(CreationPolicy.Shared)]
|
|
public class FooBar : IFooBar
|
|
{
|
|
}
|
|
|
|
public class Program
|
|
{
|
|
public static void Main()
|
|
{
|
|
var fooBar = new FooBar(); // Noncompliant;
|
|
}
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,csharp,diff-id=1,diff-type=compliant]
|
|
----
|
|
[Export(typeof(IFooBar))]
|
|
[PartCreationPolicy(CreationPolicy.Shared)]
|
|
public class FooBar : IFooBar
|
|
{
|
|
}
|
|
|
|
public class Program
|
|
{
|
|
public static void Main()
|
|
{
|
|
var fooBar = serviceProvider.GetService<IFooBar>();
|
|
}
|
|
}
|
|
----
|
|
|
|
include::../resources-dotnet.adoc[]
|
|
|
|
include::../rspecator.adoc[] |