Dmitri, it doesn't work if you pass the interface type to session.Services.Get<>()

public interface IMyService : ISessionService {}

[Service(typeof(IMyService))]
public class MyService : SessionBound, IMyService
{
    public MyService(Session session) : base(session) {}
}

...

public static void Main() {
    using (var session = Domain.OpenSession())
    using (var transactionScope = session.OpenTransaction())
        var service = session.Services.Get<IMyService>();
}

service is null!

asked Dec 30 '10 at 15:44

ara's gravatar image

ara
395878791

edited Jan 15 '11 at 19:03


2 Answers:

Ara, I think, I've got the idea.

Note the [ServiceConstructor] attribute, which is necessary for non-empty constructors.

public interface IMyService : ISessionService
{
}

[Service(typeof(IMyService))]
public class MyService : SessionBound, IMyService
{
  [ServiceConstructor]
  public MyService(Session session) :
    base(session)
  {
  }
}

I'm sorry for your inconvenience. We should have added service-related part in the manual long time ago.

answered Jan 17 '11 at 06:32

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211

FINALLY! Thank you! =)

(Jan 17 '11 at 15:34) ara ara's gravatar image

It's a pleasure =)

(Jan 17 '11 at 23:21) Dmitri Maximov Dmitri%20Maximov's gravatar image

There should be no any difference in this case. Integrated IoC container fully relies on types passed to DomainConfiguration.Types.Register method, so if there is no any difference, it should work the same.

Try to set a breakpoint in service constructor, see the stack trace when it's hit @ MVC app, and try to do the same in the test project. If BP won't be hit, try to set breakpoints @ expected callers from the MVC app stack.

If this won't expose the issue, please send us a sample. We'll try to investigate the issue here.

answered Jan 04 '11 at 15:59

Sergey's gravatar image

Sergey
123339

Can you guys confirm that with v4.4 you are able to retrieve a ISessionService instance in a project that does NOT use your SessionManager? Is there an example you can provide?

(Jan 13 '11 at 19:23) ara ara's gravatar image

Ara, I've checked the SqlDirectAccessorTest from the manual and can confirm that it doesn't fail, so the instance of SqlDirectAccessor which implements ISessionService is retrieved successfully.

(Jan 14 '11 at 08:01) Dmitri Maximov Dmitri%20Maximov's gravatar image

See my update in the original question. DirectSqlAccessor works because it is the class type. If you pass an interface type, it doesn't work.

(Jan 15 '11 at 19:03) ara ara's gravatar image

Actually, DirectSqlAccessor works because it is a native DO service.

Even passing the concrete implementation, MyService, as the type parameter doesn't work.

(Jan 15 '11 at 20:33) ara ara's gravatar image

Ara,

is your service declaration located in the same assembly as domain model? If not, are you registering types from that assembly in DomainConfiguration.Types.Register method?

(Jan 17 '11 at 04:37) Dmitri Maximov Dmitri%20Maximov's gravatar image

Same assembly. Try the example I posted.. you'll see that it doesn't work =(

(Jan 17 '11 at 04:39) ara ara's gravatar image

I even try config.Types.Register(typeof(IMyService)) and config.Types.Register(typeof(MyService)). Still doesn't work.

(Jan 17 '11 at 04:39) ara ara's gravatar image

I see.

I just wanted to be sure that I'd understood the conditions correctly. Will check this shortly.

(Jan 17 '11 at 05:02) Dmitri Maximov Dmitri%20Maximov's gravatar image

Thanks, Dmitri. And just to confirm... this is in 4.4

(Jan 17 '11 at 05:21) ara ara's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA