c# - SimpleInjector Verification - is it possible to mark warnings as acceptable to make *new* items obvious? -


the simpleinjector verification feature time time has highlighted issues have needed fix. have couple of "potential" issues comfortable , way of telling simpleinjector these ok, tell me rest ...

  • configuration warnings warnings in multiple groups have been detected.
    • potential lifestyle mismatches 1 possible mismatch 1 service.
      • iobjectmaterializedsubscriber objectmaterializedsubscriber (lifetime scope) depends on ieventpublisher (transient).
    • potential single responsibility violations 2 possible violations.
      • ilettergenerator<a> lettergenerator<a> has 9 dependencies might indicate srp violation.
      • ilettergenerator<b> lettergenerator<b> has 9 dependencies might indicate srp violation.

the first warning ieventpublisher transient fine. other 2 warnings (i assuming) caused me using simpleinjector decorator facility build chains of responsibility.

i'd able mark these specific warnings accepted container can report appears ok!

is possible?

i'd able mark these specific warnings accepted [...] possible?

no, there no way current (2.2.3) release. whole diagnostic api internal. possible trigger diagnostic validation using reflection in unit test , filter out warnings you're not interested in. if there warnings left, can let test fail.

this possible, require work, , in cases wouldn't want have potential lifestyle mismatch violations. documentation potential lifestyle mismatches states:

do not ignore these warnings. false positives warning rare , when occur, registration or application design can changed in way warning disappears.

in case lifetime scoped instance refers transient , seem aware of possible risk of , seem have checked not problem. still, become problem in future when class changed, , other developers mislead if don't document explicitly.

there multiple ways fix this. instance, can promote transient dependency lifetime scope, have considered this. option let objectmaterializedsubscriber not depend on transient ieventpublisher, on singleton func<ieventpublisher>, can registered follows:

container.registersingle<func<ieventpublisher>>(     () => container.getinstance<ieventpublisher>()); 

this makes code of objectmaterializedsubscriber communicate expects object shorter lifestyle, if ieventpublisher requested once.

the other 2 warnings (i assuming) caused me using simpleinjector decorator facility build chains of responsibility.

unfortunately, stumbled upon bug in 2.2.1 release. problem wasn't caused adding decorators, use of unregistered type resolution. bug has been fixed in 2.2.3.

update

since simple injector 2.4 there's diagnostics api allows interact programmatically diagnostic services. allows write unit tests , filter out unwanted warnings before letting unit test verify if free of warnings. example:

[testmethod] public void container_always_containsnodiagnosticwarnings() {     // arrange     var container = bootstrapper.getinitializedcontainer();      container.verify();      // assert     var results = analyzer.analyze(container);      assert.isfalse(results.any(), environment.newline +         string.join(environment.newline,             result in results             select result.description)); } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -